otw_breadcrumb

The Carbon Light - Business responsive otw breadcrumb function.

Description

otw_breadcrumb(); 

Usage

  1. if ( !function_exists( 'otw_breadcrumb' ) ) { 
  2. require_once '/functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = otw_breadcrumb(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/functions.php  
  1. function otw_breadcrumb() { 
  2.  
  3. /** === OPTIONS === */ 
  4. $text['home'] = __('Home', 'otw-carbon-light'); // text for the 'Home' link 
  5. $text['category'] = __('Archive for %s', 'otw-carbon-light'); // text for a category page 
  6. $text['search'] = __('Search results for: %s', 'otw-carbon-light'); // text for a search results page 
  7. $text['tag'] = __('Posts tagged %s', 'otw-carbon-light'); // text for a tag page 
  8. $text['author'] = __('View all posts by %s', 'otw-carbon-light'); // text for an author page 
  9. $text['404'] = __('Error 404', 'otw-carbon-light'); // text for the 404 page 
  10.  
  11. $showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show 
  12. $showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show 
  13. $delimiter = ' » '; // delimiter between crumbs 
  14. $before = '<span class="current">'; // tag before the current crumb 
  15. $after = '</span>'; // tag after the current crumb 
  16. /** === END OF OPTIONS === */ 
  17.  
  18. global $post; 
  19. $homeLink = get_home_url('url') . '/'; 
  20. $linkBefore = '<span typeof="v:Breadcrumb">'; 
  21. $linkAfter = '</span>'; 
  22. $linkAttr = ' rel="v:url" property="v:title"'; 
  23. $link = $linkBefore . '<a' . $linkAttr . ' href="%1$s">%2$s</a>' . $linkAfter; 
  24.  
  25. if (is_home() || is_front_page()) { 
  26.  
  27. if ($showOnHome == 1) echo '<div id="breadcrumb"><a href="' . $homeLink . '">' . $text['home'] . '</a></div>'; 
  28.  
  29. } else { 
  30.  
  31. echo '<div id="breadcrumb">' . sprintf($link, $homeLink, $text['home']) . $delimiter; 
  32.  
  33. if ( is_category() ) { 
  34. $thisCat = get_category(get_query_var('cat'), false); 
  35. if ($thisCat->parent != 0) { 
  36. $cats = get_category_parents($thisCat->parent, TRUE, $delimiter); 
  37. $cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats); 
  38. $cats = str_replace('</a>', '</a>' . $linkAfter, $cats); 
  39. echo $cats; 
  40. echo $before . sprintf($text['category'], single_cat_title('', false)) . $after; 
  41.  
  42. } elseif ( is_search() ) { 
  43. echo $before . sprintf($text['search'], get_search_query()) . $after; 
  44.  
  45. } elseif ( is_day() ) { 
  46. echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter; 
  47. echo sprintf($link, get_month_link(get_the_time('Y'), get_the_time('m')), get_the_time('F')) . $delimiter; 
  48. echo $before . get_the_time('d') . $after; 
  49.  
  50. } elseif ( is_month() ) { 
  51. echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter; 
  52. echo $before . get_the_time('F') . $after; 
  53.  
  54. } elseif ( is_year() ) { 
  55. echo $before . get_the_time('Y') . $after; 
  56.  
  57. } elseif ( is_single() && !is_attachment() ) { 
  58. if ( get_post_type() != 'post' ) { 
  59. $post_type = get_post_type_object(get_post_type()); 
  60. $slug = $post_type->rewrite; 
  61. printf($link, $homeLink . '/' . $slug['slug'] . '/', $post_type->labels->singular_name); 
  62. //echo get_the_term_list( $post->ID, 'portfolio-category', '', ', ', '' ) ; // taxonomy fix to display all 
  63.  
  64. if ($showCurrent == 1) echo $delimiter . $before . get_the_title() . $after; 
  65. } else { 
  66. $cat = get_the_category(); $cat = $cat[0]; 
  67. $cats = get_category_parents($cat, TRUE, $delimiter); 
  68. if ($showCurrent == 0) $cats = preg_replace("#^(.+)$delimiter$#", "$1", $cats); 
  69. $cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats); 
  70. $cats = str_replace('</a>', '</a>' . $linkAfter, $cats); 
  71. echo $cats; 
  72. if ($showCurrent == 1) echo $before . get_the_title() . $after; 
  73.  
  74. } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) { 
  75. $post_type = get_post_type_object(get_post_type()); 
  76. echo $before . $post_type->labels->singular_name . $after; 
  77.  
  78. } elseif ( is_attachment() ) { 
  79. $parent = get_post($post->post_parent); 
  80. $cat = get_the_category($parent->ID); $cat = $cat[0]; 
  81. $cats = get_category_parents($cat, TRUE, $delimiter); 
  82. $cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats); 
  83. $cats = str_replace('</a>', '</a>' . $linkAfter, $cats); 
  84. echo $cats; 
  85. printf($link, get_permalink($parent), $parent->post_title); 
  86. if ($showCurrent == 1) echo $delimiter . $before . get_the_title() . $after; 
  87.  
  88. } elseif ( is_page() && !$post->post_parent ) { 
  89. if ($showCurrent == 1) echo $before . get_the_title() . $after; 
  90.  
  91. } elseif ( is_page() && $post->post_parent ) { 
  92. $parent_id = $post->post_parent; 
  93. $breadcrumbs = array(); 
  94. while ($parent_id) { 
  95. $page = get_page($parent_id); 
  96. $breadcrumbs[] = sprintf($link, get_permalink($page->ID), get_the_title($page->ID)); 
  97. $parent_id = $page->post_parent; 
  98. $breadcrumbs = array_reverse($breadcrumbs); 
  99. for ($i = 0; $i < count($breadcrumbs); $i++) { 
  100. echo $breadcrumbs[$i]; 
  101. if ($i != count($breadcrumbs)-1) echo $delimiter; 
  102. if ($showCurrent == 1) echo $delimiter . $before . get_the_title() . $after; 
  103.  
  104. } elseif ( is_tag() ) { 
  105. echo $before . sprintf($text['tag'], single_tag_title('', false)) . $after; 
  106.  
  107. } elseif ( is_author() ) { 
  108. global $author; 
  109. $userdata = get_userdata($author); 
  110. echo $before . sprintf($text['author'], $userdata->display_name) . $after; 
  111.  
  112. } elseif ( is_404() ) { 
  113. echo $before . $text['404'] . $after; 
  114.  
  115. if ( get_query_var('paged') ) { 
  116. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' ('; 
  117. echo __('Page', 'otw-carbon-light') . ' ' . get_query_var('paged'); 
  118.  
  119. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')'; 
  120.  
  121. echo '</div>'; 
  122.  
  123. } // end dimox_breadcrumbs()