responsive_II_breadcrumb_lists

The Responsive II responsive II breadcrumb lists function.

Description

responsive_II_breadcrumb_lists(); 

Usage

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

Defined (1)

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

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