catchresponsive_custom_breadcrumbs

The Catch Responsive catchresponsive custom breadcrumbs function.

Description

catchresponsive_custom_breadcrumbs( $showOnHome, $delimiter ); 

Parameters (2)

0. $showonhome
The showonhome.
1. $delimiter
The delimiter.

Usage

  1. if ( !function_exists( 'catchresponsive_custom_breadcrumbs' ) ) { 
  2. require_once '/inc/catchresponsive-breadcrumb.php'; 
  3.  
  4. // The showonhome. 
  5. $showonhome = null; 
  6.  
  7. // The delimiter. 
  8. $delimiter = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = catchresponsive_custom_breadcrumbs($showonhome, $delimiter); 
  12.  

Defined (1)

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

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