Want more features on Pastebin? Sign Up, it's FREE!

Untitled

By: kristinachilds on Oct 24th, 2012  |  syntax: None  |  size: 4.93 KB  |  views: 7  |  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. // add support for breadcrumbs (from dimox.net)
  2. function the_breadcrumbs() {
  3.  
  4.   $showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
  5.   $delimiter = '»'; // delimiter between crumbs
  6.   $home = 'Home'; // text for the 'Home' link
  7.   $showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
  8.   $before = '<span class="current">'; // tag before the current crumb
  9.   $after = '</span>'; // tag after the current crumb
  10.  
  11.   global $post;
  12.   $homeLink = get_bloginfo('url');
  13.  
  14.   if (is_home() || is_front_page()) {
  15.  
  16.     if ($showOnHome == 1) echo '<div id="breadcrumbs"><a href="' . $homeLink . '">' . $home . '</a></div>';
  17.  
  18.   } else {
  19.  
  20.     echo '<div id="breadcrumbs"><a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' ';
  21.  
  22.     if ( is_category() ) {
  23.       $thisCat = get_category(get_query_var('cat'), false);
  24.       if ($thisCat->parent != 0) echo get_category_parents($thisCat->parent, TRUE, ' ' . $delimiter . ' ');
  25.       echo single_cat_title('', false);
  26.  
  27.     } elseif ( is_search() ) {
  28.       echo $before . 'Search results for "' . get_search_query() . '"' . $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>';
  47.         if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . substr(the_title('', '', FALSE), 0, 40) . $after;
  48.       } else {
  49.         $cat = get_the_category(); $cat = $cat[0];
  50.         $cats = get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
  51.         if ($showCurrent == 0) $cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
  52.         echo $cats;
  53.         if (($showCurrent == 1) && (strlen($post->post_title) > 40)) echo $before . substr(the_title('', '', FALSE), 0, 40) . '...' . $after;
  54.         if (($showCurrent == 1) && (strlen($post->post_title) < 40)) echo $before . get_the_title() . $after;
  55.                
  56.       }
  57.  
  58.     } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
  59.       $post_type = get_post_type_object(get_post_type());
  60.       echo $before . $post_type->labels->singular_name . $after;
  61.  
  62.     } elseif ( is_attachment() ) {
  63.       $parent = get_post($post->post_parent);
  64.       $cat = get_the_category($parent->ID); $cat = $cat[0];
  65.       echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
  66.       echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a>';
  67.       if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . substr(the_title('', '', FALSE), 0, 40) . $after;
  68.  
  69.     } elseif ( is_page() && !$post->post_parent ) {
  70.       if ($showCurrent == 1) echo $before . substr(the_title('', '', FALSE), 0, 40) . $after;
  71.  
  72.     } elseif ( is_page() && $post->post_parent ) {
  73.       $parent_id  = $post->post_parent;
  74.       $breadcrumbs = array();
  75.       while ($parent_id) {
  76.         $page = get_page($parent_id);
  77.         $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
  78.         $parent_id  = $page->post_parent;
  79.       }
  80.       $breadcrumbs = array_reverse($breadcrumbs);
  81.       for ($i = 0; $i < count($breadcrumbs); $i++) {
  82.         echo $breadcrumbs[$i];
  83.         if ($i != count($breadcrumbs)-1) echo ' ' . $delimiter . ' ';
  84.       }
  85.       if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . substr(the_title('', '', FALSE), 0, 40) . $after;
  86.  
  87.     } elseif ( is_tag() ) {
  88.       echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;
  89.  
  90. //    } elseif ( is_author() ) {
  91. //       global $author;
  92. //      $userdata = get_userdata($author);
  93. //      echo $before . 'Articles posted by ' . $userdata->display_name . $after;
  94.  
  95.     } elseif ( is_404() ) {
  96.       echo $before . 'Error 404' . $after;
  97.     }
  98.  
  99.     if ( get_query_var('paged') ) {
  100.       if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
  101.       echo __('Page') . ' ' . get_query_var('paged');
  102.       if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
  103.     }
  104.  
  105.     echo '</div>';
  106.  
  107.   }
  108. } // end the_breadcrumbs()
clone this paste RAW Paste Data