WordPress Breadcrumbs for Pages

Breadcrumbs are very useful navigation tools, especially for sites with multiple levels and more than a dozen pages.  While there are a few breadcrumb navigation plugins for WordPress, sometimes it’s a bit of an overkill when the job can be done with just a few lines of code.

The function below will insert a breadcrumb navigation for the pages in your WP site, and highlight the news/blog page when within that section, etc.

Usage:

  1. Copy the code below into your theme’s functions.php file.  If your theme doesn’t have one, create it.
  2. //breadcrumb function
    function rm_bread_crumbs() {
     global $post;
     $crumbs =     '<p><a href="'.get_option('home').'">Home</a>';
    
     //if the page has a parent add title and link of parent
     if($post->post_parent) {
     $crumbs .=     ' &raquo; <a href="'.get_permalink($post->post_parent).'">'.get_the_title($post->post_parent).'</a>';
     }
    
     // if it's not the front page of the site, but isn't the blog either
     if((!is_front_page()) && (is_page())) {
     $crumbs .=    ' &raquo; '.get_the_title($post->ID);
     }
    
     //if it's the news/blog home page or any type of archive
     if((is_home() ||(is_archive()))) {
     $crumbs .=    ' &raquo; '.get_the_title(get_option(page_for_posts));
     }
    
     //if it's a single news/blog post
     if(is_single()) {
     $crumbs .=     ' &raquo; <a href="'.get_permalink(get_option(page_for_posts)).'">'.get_the_title(get_option(page_for_posts)).'</a>';
     $crumbs .=    ' &raquo; '.get_the_title($post->ID);
     }
     $crumbs .=    '</p>'."\n";
     echo $crumbs;
    }
  3. Insert <?php rm_bread_crumbs(); ?> in your theme where ever you’d like the bread crumbs displayed.

A RSS News Ticker for WordPress & jQuery

It’s actually quite easy to add a horizontally scrolling news ticker using jQuery, WordPress, and Gian Carlo Mingati’s liscroll() plugin for jQuery.  There are really only two steps, so we’re skipping the full on demo this time…

1.) Include the files for liscroll() (the CSS file, javascript file, and of course jQuery itself). Then call the plugin as described in the author’s web page…

2.) Use WordPress’s built in RSS feed parsing and caching mechanisms. Simply edit the RSS URL for the feed you’d like to display, and paste the below code in your theme where you’d like the scroll bar to appear.

<?php include_once(ABSPATH.WPINC.'/rss.php'); // path to include script $feed = fetch_rss('http://yourRSSfeedhere.com/feed/'); // specify feed url $items = array_slice($feed->items, 0, 7); // specify first and last item ?>  <?php if (!empty($items)) : ?> <ul id="ticker01"> <?php foreach ($items as $item) : ?> <li><a href="<?php echo $item['link']; ?>"><?php echo $item['title']; ?></a><span><?php echo $item['pubdate']; ?></span></li> <?php endforeach; ?> </ul> <?php endif; ?> <? } ?>

To see it in action, check out PGB Associates home page (bottom)…