This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

WordPress Breadcrumbs

By: a guest on Apr 18th, 2012  |  syntax: PHP  |  size: 4.26 KB  |  views: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function custom_breadcrumbs() {
  2.  
  3.   $showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
  4.   $delimiter = '»&raquo'; // delimiter between crumbs
  5.   $home = 'Hitchhiking Hub'; // text for the 'Home' link
  6.   $showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
  7.   $before = '<span class="current">'; // tag before the current crumb
  8.   $after = '</span>'; // tag after the current crumb
  9.  
  10.   global $post;
  11.   $homeLink = get_bloginfo('url');
  12.  
  13.   if (is_home() || is_front_page()) {
  14.  
  15.         if ($showOnHome == 1) echo '<div id="crumbs"><a href="' . $homeLink . '">' . $home . '</a></div>';
  16.  
  17.   } else {
  18.  
  19.         echo '<div id="crumbs"><a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' ';
  20.  
  21.         if ( is_category() ) {
  22.           global $wp_query;
  23.           $cat_obj = $wp_query->get_queried_object();
  24.           $thisCat = $cat_obj->term_id;
  25.           $thisCat = get_category($thisCat);
  26.           $parentCat = get_category($thisCat->parent);
  27.           if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
  28.           echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after;
  29.  
  30.         } elseif ( is_day() ) {
  31.           echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
  32.           echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
  33.           echo $before . get_the_time('d') . $after;
  34.  
  35.         } elseif ( is_month() ) {
  36.           echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
  37.           echo $before . get_the_time('F') . $after;
  38.  
  39.         } elseif ( is_year() ) {
  40.           echo $before . get_the_time('Y') . $after;
  41.  
  42.         } elseif ( is_single() && !is_attachment() ) {
  43.           if ( get_post_type() != 'post' ) {
  44.                 $post_type = get_post_type_object(get_post_type());
  45.                 $slug = $post_type->rewrite;
  46.                 echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';
  47.                 if ($showCurrent == 1) echo $before . get_the_title() . $after;
  48.           } else {
  49.                 $cat = get_the_category(); $cat = $cat[0];
  50.                 echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
  51.                 if ($showCurrent == 1) echo $before . get_the_title() . $after;
  52.           }
  53.  
  54.         } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
  55.           $post_type = get_post_type_object(get_post_type());
  56.           echo $before . $post_type->labels->singular_name . $after;
  57.  
  58.         } elseif ( is_attachment() ) {
  59.           $parent = get_post($post->post_parent);
  60.           $cat = get_the_category($parent->ID); $cat = $cat[0];
  61.           echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
  62.           echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
  63.           if ($showCurrent == 1) echo $before . get_the_title() . $after;
  64.  
  65.         } elseif ( is_page() && !$post->post_parent ) {
  66.           if ($showCurrent == 1) echo $before . get_the_title() . $after;
  67.  
  68.         } elseif ( is_page() && $post->post_parent ) {
  69.           $parent_id  = $post->post_parent;
  70.           $breadcrumbs = array();
  71.           while ($parent_id) {
  72.                 $page = get_page($parent_id);
  73.                 $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
  74.                 $parent_id  = $page->post_parent;
  75.           }
  76.           $breadcrumbs = array_reverse($breadcrumbs);
  77.           foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
  78.           if ($showCurrent == 1) echo $before . get_the_title() . $after;
  79.  
  80.         } elseif ( is_search() ) {
  81.           echo $before . 'Search results for "' . get_search_query() . '"' . $after;
  82.  
  83.         } elseif ( is_tag() ) {
  84.           echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;
  85.  
  86.         } elseif ( is_author() ) {
  87.            global $author;
  88.           $userdata = get_userdata($author);
  89.           echo $before . 'Articles posted by ' . $userdata->display_name . $after;
  90.  
  91.         } elseif ( is_404() ) {
  92.           echo $before . 'Error 404' . $after;
  93.         }
  94.  
  95.         if ( get_query_var('paged') ) {
  96.           if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
  97.           echo __('Page') . ' ' . get_query_var('paged');
  98.           if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
  99.         }
  100.  
  101.         echo '</div>';
  102.  
  103.   }
  104. }
clone this paste RAW Paste Data