responsive_breadcrumb_lists

The Responsive responsive breadcrumb lists function.

Description

responsive_breadcrumb_lists(); 

Usage

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

Defined (1)

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

/includes/functions.php  
  1. function responsive_breadcrumb_lists() { 
  2. $options = get_theme_mod( 'breadcrumbs' ); 
  3.  
  4. if ( 'no' == $options ) { 
  5. return; 
  6. } else { 
  7.  
  8. $chevron = '<span class="chevron">›</span>'; 
  9. $home = __('Home', 'responsive'); // text for the 'Home' link 
  10. $before = '<span class="breadcrumb-current">'; // tag before the current crumb 
  11. $after = '</span>'; // tag after the current crumb 
  12.  
  13. if ( ! is_home() && ! is_front_page() || is_paged() ) { 
  14.  
  15. echo '<div class="breadcrumb-list">'; 
  16.  
  17. global $post; 
  18. $homeLink = home_url( '/' ); 
  19.  
  20. echo '<a href="' . esc_url( $homeLink ) . '">' . $home . '</a> ' . $chevron . ' '; 
  21.  
  22. if ( is_category() ) { 
  23. global $wp_query; 
  24.  
  25. $cat_obj = $wp_query->get_queried_object(); 
  26. $thisCat = $cat_obj->term_id; 
  27. $thisCat = get_category( $thisCat ); 
  28. $parentCat = get_category( $thisCat->parent ); 
  29. $cat_parents = get_category_parents( $parentCat, TRUE, ' ' . $chevron . ' ' ); 
  30.  
  31. if ( $thisCat->parent != 0 && ! is_wp_error( $cat_parents ) ) 
  32. echo $cat_parents; 
  33.  
  34. echo $before; printf( __( 'Archive for %s', 'responsive' ), single_cat_title('', false) ); $after; 
  35.  
  36. } elseif ( is_day() ) { 
  37.  
  38. echo '<a href="' . esc_url( get_year_link( get_the_time( 'Y' ) ) ) . '">' . get_the_time( 'Y' ) . '</a> ' . $chevron . ' <a href="' . esc_url( get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) ) . '">' . get_the_time( 'F' ) . '</a> ' . $chevron . ' ' . before . get_the_time( 'd' ) . $after; 
  39.  
  40. } elseif ( is_month() ) { 
  41.  
  42. echo '<a href="' . esc_url( get_year_link(get_the_time( 'Y' ) ) ) . '">' . get_the_time( 'Y' ) . '</a> ' . $chevron . ' ' . $before . get_the_time( 'F' ) . $after; 
  43.  
  44. } elseif ( is_year() ) { 
  45.  
  46. echo $before . get_the_time( 'Y' ) . $after; 
  47.  
  48. } elseif ( is_single() && ! is_attachment() ) { 
  49.  
  50. if ( 'post' != get_post_type() ) { 
  51. $post_type = get_post_type_object( get_post_type() ); 
  52. $slug = $post_type->rewrite; 
  53. $post_type_link = $homeLink . '/' . $slug['slug'] . '/'; 
  54.  
  55. echo '<a href="' . esc_url( $post_type_link ) . '">' . $post_type->labels->singular_name . '</a> ' . $chevron . ' ' . $before . get_the_title() . $after; 
  56.  
  57. } else { 
  58.  
  59. $cat = get_the_category(); $cat = $cat[0]; 
  60. $cat_parents = get_category_parents( $cat, TRUE, ' ' . $chevron . ' ' ); 
  61.  
  62. if ( ! is_wp_error( $cat_parents ) ) 
  63. echo $cat_parents . $before . get_the_title() . $after; 
  64.  
  65.  
  66. } elseif ( ! is_single() && ! is_page() && get_post_type() != 'post' && ! is_404() ) { 
  67.  
  68. $post_type = get_post_type_object( get_post_type() ); 
  69.  
  70. echo $before . $post_type->labels->singular_name . $after; 
  71.  
  72. } elseif ( is_attachment() ) { 
  73.  
  74. $parent = get_post( $post->post_parent ); 
  75. $cat = get_the_category( $parent->ID ); $cat = $cat[0]; 
  76. $cat_parents = get_category_parents( $cat, TRUE, ' ' . $chevron . ' ' ); 
  77.  
  78. if ( ! is_wp_error( $cat_parents ) ) 
  79. echo $cat_parents . '<a href="' . esc_url( get_permalink($parent) ) . '">' . $parent->post_title . '</a> ' . $chevron . ' ' . $before . get_the_title() . $after; 
  80.  
  81. } elseif ( is_page() && ! $post->post_parent ) { 
  82.  
  83. echo $before . get_the_title() . $after; 
  84.  
  85. } elseif ( is_page() && $post->post_parent ) { 
  86.  
  87. $parent_id = $post->post_parent; 
  88. $breadcrumbs = array(); 
  89.  
  90. while ($parent_id) { 
  91. $page = get_page( $parent_id ); 
  92. $breadcrumbs[] = '<a href="' . esc_url( get_permalink( $page->ID ) ) . '">' . get_the_title( $page->ID ) . '</a>'; 
  93. $parent_id = $page->post_parent; 
  94.  
  95. $breadcrumbs = array_reverse( $breadcrumbs ); 
  96.  
  97. foreach ( $breadcrumbs as $crumb ) 
  98. echo $crumb . ' ' . $chevron . ' '; 
  99.  
  100. echo $before . get_the_title() . $after; 
  101.  
  102. } elseif ( is_search() ) { 
  103.  
  104. echo $before; sprintf( __( 'Search results for: %s', 'responsive' ), get_search_query() ); $after; 
  105.  
  106. } elseif ( is_tag() ) { 
  107.  
  108. echo $before . sprintf( __( 'Posts tagged %s', 'responsive' ), single_tag_title( '', false ) ) . $after; 
  109.  
  110. } elseif ( is_author() ) { 
  111.  
  112. global $author; 
  113.  
  114. $userdata = get_userdata($author); 
  115.  
  116. echo $before . sprintf( __( 'View all posts by %s', 'responsive' ), $userdata->display_name ) . $after; 
  117.  
  118. } elseif ( is_404() ) { 
  119. echo $before . __('Error 404 ', 'responsive') . $after; 
  120.  
  121. if ( get_query_var('paged') ) { 
  122. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) 
  123. echo ' ('; 
  124.  
  125. echo __('Page', 'responsive') . ' ' . get_query_var('paged'); 
  126.  
  127. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) 
  128. echo ')'; 
  129.  
  130. echo '</div>'; 
  131.