Add Breadcrumb Navigation

Supplemental 29 views
0
0 Flares 0 Flares ×

There are plenty of breadcrumb navigation plugins out there. But with this you can hardcode it into your theme yourself.

This would be placed in the functions.php file within your theme directory.

<?php // Add Breadcrumb Navigation, original article on: http://wpti.ps/?p=37
function so_write_breadcrumb() {
    $pid = $post->ID;
 $trail = '<a href="/">'. __('Home', 'so-base') .'</a>';
 
    if (is_front_page()) {
        // do nothing
	}
		elseif (is_page()) {
			$bcarray = array();
			$pdata = get_post($pid);
			$bcarray[] = ' » '.$pdata->post_title."\n";
			while ($pdata->post_parent) {
				$pdata = get_post($pdata->post_parent);
				$bcarray[] = ' » <a href="'.get_permalink($pdata->ID).'">'.$pdata->post_title.'</a>';
			}
		   $bcarray = array_reverse($bcarray);
			 foreach ($bcarray AS $listitem) {
				 $trail .= $listitem;
			 }
		}
		elseif (is_single()) {
			$pdata = get_the_category($pid);
			$adata = get_post($pid);
			if(!empty($pdata)){
				$data = get_category_parents($pdata[0]->cat_ID, TRUE, ' » ');
				$trail .= " » ".substr($data,0,-8);
			}
			$trail.= ' » '.$adata->post_title."\n";
		}
	   	elseif (is_category()) {
			$pdata = get_the_category($pid);
			$data = get_category_parents($pdata[0]->cat_ID, TRUE, ' » ');
			if(!empty($pdata)){
				$trail .= " » ".substr($data,0,-8);
			}
	   	}
 $trail.="";
 return $trail;
}

For Reference:

Breadcrumb Navigation

Provided by: Piet Bos
Tagged with:
Posted in Wordpress

Discuss:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

No Trackbacks.

Login

Register | Lost your password?
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×