Guest User

Untitled

a guest
Aug 15th, 2018
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. <?php
  2. function qt_custom_breadcrumbs() {
  3.  
  4. $showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
  5. $delimiter = ''; // delimiter between crumbs
  6. $home = __('Home','appointment'); // text for the 'Home' link
  7. $showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
  8. $before = '<li class="active">'; // tag before the current crumb
  9. $after = '</li>'; // tag after the current crumb
  10.  
  11. global $post;
  12. $homeLink = home_url();
  13.  
  14. if (is_home() || is_front_page()) {
  15.  
  16. if ($showOnHome == 1) echo '<li><a href="' . $homeLink . '">' . $home . '</a></li>';
  17.  
  18. } else {
  19.  
  20. echo '<li><a href="' . $homeLink . '">' . $home . '</a> ' . '&nbsp &#47; &nbsp';
  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, ' ' . ' ');
  25. echo $before . __('Archive by category','appointment') . $after;
  26.  
  27. } elseif ( is_search() ) {
  28. echo $before . __('Search results for','appointment').' "' . 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> ' . '&nbsp &#47; &nbsp';
  32. echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . '&nbsp &#47; &nbsp';
  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 . '&nbsp &#47; &nbsp';
  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 . '&nbsp &#47; &nbsp' . $before . get_the_title() . $after;
  48. } else {
  49. $cat = get_the_category(); $cat = $cat[0];
  50. $cats = get_category_parents($cat, TRUE, ' ' . $delimiter . '&nbsp &#47; &nbsp');
  51. if ($showCurrent == 0) $cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
  52. echo $cats;
  53. if ($showCurrent == 1) echo $before . get_the_title() . $after;
  54. }
  55.  
  56. } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
  57. if ( class_exists( 'WooCommerce' ) ) {
  58. if ( is_shop() ) {
  59. $thisshop = woocommerce_page_title();
  60. }
  61. }else{
  62. $post_type = get_post_type_object(get_post_type());
  63. echo $before . $post_type->labels->singular_name . $after;
  64. }
  65. }
  66. elseif ( is_attachment() ) {
  67. $parent = get_post($post->post_parent);
  68. $cat = get_the_category($parent->ID);
  69. if(!empty($cat)){
  70. $cat = $cat[0];
  71. echo get_category_parents($cat, TRUE, ' ' . $delimiter . '&nbsp &#47; &nbsp');
  72. }
  73. echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a>';
  74. if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
  75.  
  76. } elseif ( is_page() && !$post->post_parent ) {
  77. if ($showCurrent == 1) echo $before . get_the_title() . $after;
  78.  
  79. } elseif ( is_page() && $post->post_parent ) {
  80. $parent_id = $post->post_parent;
  81. $breadcrumbs = array();
  82. while ($parent_id) {
  83. $page = get_page($parent_id);
  84. $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>' . '&nbsp &#47; &nbsp';
  85. $parent_id = $page->post_parent;
  86. }
  87. $breadcrumbs = array_reverse($breadcrumbs);
  88. for ($i = 0; $i < count($breadcrumbs); $i++) {
  89. echo $breadcrumbs[$i];
  90. if ($i != count($breadcrumbs)-1) echo ' ' . $delimiter;
  91. }
  92. if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
  93.  
  94. } elseif ( is_tag() ) {
  95. echo $before . __('Posts tagged','appointment').' "' . single_tag_title('', false) . '"' . $after;
  96.  
  97. } elseif ( is_author() ) {
  98. global $author;
  99. $userdata = get_userdata($author);
  100. echo $before . __('Articles posted by','appointment').' ' . $userdata->display_name . $after;
  101.  
  102. } elseif ( is_404() ) {
  103. echo $before . __('Error 404','appointment') . $after;
  104. }
  105.  
  106. if ( get_query_var('paged') ) {
  107. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo '';
  108. echo ' ( ' . __('Page','appointment') . '' . get_query_var('paged'). ' )';
  109. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo '';
  110. }
  111.  
  112. echo '</li>';
  113.  
  114. }
  115. } // end qt_custom_breadcrumbs()
  116. ?>
Add Comment
Please, Sign In to add comment