How To Get An RSS Feed And Display Items With A Loop
Use of the following snippet will let you get an RSS feed and display items with a loop.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php include_once(ABSPATH . WPINC . '/rss.php'); $feed = 'http://dangayle.com/feed/'; $rss = fetch_feed($feed); if (!is_wp_error( $rss ) ) : $maxitems = $rss->get_item_quantity(3); $rss_items = $rss->get_items(0, $maxitems); if ($rss_items): echo "<ul>\n"; foreach ( $rss_items as $item ) : //instead of a bunch of string concatenation or echoes, I prefer the terseness of printf //(http://php.net/manual/en/function.printf.php) printf('<li><a href="%s">%s</a><p>%s</p></li>',$item->get_permalink(),$item->get_title(),$item->get_description() ); endforeach; echo "</ul>\n"; endif; endif; ?> |
Snippet Source/Credit: DanGayle.com
How To Get Attachments For Post Or Page
Using the following snippet below will let you get attachments for posts or pages.
1 2 3 4 5 6 7 8 9 |
$args = array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $post->ID ); $images = get_posts( $args ); foreach($images as $image): echo wp_get_attachment_image($image->ID, 'medium'); endforeach; |
Snippet Source/Credit: Stack Overflow
How To Have Custom Menus For Different Category/Page/Post
The following snippet will let you have custom menus for different category, page or post respectively.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<?php // add the following to wp theme function.php register_nav_menus( array( 'primary-menu' => 'main menu', 'marketing-menu' => 'marketing menu', 'shopping menu' => 'shopping menu', 'technology menu' => 'technology menu', 'recreation menu' => 'recreation menu', ) ); add_action( 'init', 'register_nav_menus' ); ?> <?php // add following to where you want the menu share, in my case, hearder.php <?php if((has_nav_menu('marketing-menu') and !is_home() and is_category(array(5,6,8,9,10,11,12,13,14))) or (has_nav_menu('marketing-menu') and !is_home() and in_category(array(5,6,8,9,10,11,12,13,14)))) { wp_nav_menu(array( 'theme_location' => 'marketing-menu', 'container' => '', 'menu_id' => 'primary-nav', 'container_class' => 'main-menu', 'menu_class' => 'nav' )); } else(has_nav_menu('primary-menu')){ wp_nav_menu(array( 'theme_location' => 'primary-menu', 'container' => '', 'menu_id' => 'primary-nav', 'container_class' => 'main-menu', 'menu_class' => 'nav' )); ?> |
Snippet Source/Credit: WordPress Code 1, 2, 3, 4
How To Remove WordPress Version Meta
Using the following snippet in your theme’s functions.php file, you will be able to remove WordPress version meta.
1 |
remove_action('wp_head', 'wp_generator'); |
How To Have WordPress Domain Check
Using the following snippet will let you have your WordPress domain check.
1 2 3 4 5 6 7 8 9 10 |
<?php $loc = $_SERVER['REQUEST_URI']; $locDomain = $_SERVER['HTTP_HOST']; $posDomain = strpos($locDomain, 'travismathew.ca'); ?> <?php if ($posDomain !== false) { ?> <!-- CANADIAN --> <?php } else { ?> <!-- UNITED STATES --> <?php } ?> |
Snippet Source/Credit: Snipplr