Posted By

Amistyle on 09/24/12


Tagged

wordpress breadcrumb


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

zemonte


Breadcrumb Wordpress


 / Published in: PHP
 

<?php>

  1. function breadcrumbs()
  2. {
  3. $delimiter = '&raquo;';
  4. $name = 'FÅ‘oldal';
  5. $currentBefore = '<span class="current">';
  6. $currentAfter = '</span>';
  7.  
  8. global $post;
  9. $home = get_bloginfo('url');
  10.  
  11. if(is_home() && get_query_var('paged') == 0)
  12. echo '<span class="home">' . $name . '</span>';
  13. else
  14. echo '<a class="home" href="' . $home . '">' . $name . '</a> '. $delimiter . ' ';
  15.  
  16. if ( is_category() )
  17. {
  18. global $wp_query;
  19. $cat_obj = $wp_query->get_queried_object();
  20. $thisCat = $cat_obj->term_id;
  21. $thisCat = get_category($thisCat);
  22. $parentCat = get_category($thisCat->parent);
  23. if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
  24. echo $currentBefore;
  25. single_cat_title();
  26. echo $currentAfter;
  27.  
  28. }
  29. elseif ( is_day() )
  30. {
  31. echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
  32. echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
  33. echo $currentBefore . get_the_time('d') . $currentAfter;
  34. }
  35. elseif ( is_month() )
  36. {
  37. echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
  38. echo $currentBefore . get_the_time('F') . $currentAfter;
  39. }
  40. elseif ( is_year() )
  41. {
  42. echo $currentBefore . get_the_time('Y') . $currentAfter;
  43. }
  44. elseif ( is_single() )
  45. {
  46. $cat = get_the_category(); $cat = $cat[0];
  47. echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
  48. echo $currentBefore;
  49. the_title();
  50. echo $currentAfter;
  51. }
  52. elseif ( is_page() && !$post->post_parent )
  53. {
  54. echo $currentBefore;
  55. the_title();
  56. echo $currentAfter;
  57. }
  58. elseif ( is_page() && $post->post_parent )
  59. {
  60. $parent_id = $post->post_parent;
  61. $breadcrumbs = array();
  62. while ($parent_id)
  63. {
  64. $page = get_page($parent_id);
  65. $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
  66. $parent_id = $page->post_parent;
  67. }
  68. $breadcrumbs = array_reverse($breadcrumbs);
  69. foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
  70. echo $currentBefore;
  71. the_title();
  72. echo $currentAfter;
  73. }
  74. elseif ( is_search() )
  75. {
  76. echo $currentBefore . 'Search for ' . get_search_query() . $currentAfter;
  77. }
  78. elseif ( is_tag() )
  79. {
  80. echo $currentBefore;
  81. single_tag_title();
  82. echo $currentAfter;
  83. }
  84. elseif ( is_author() )
  85. {
  86. global $author;
  87. $userdata = get_userdata($author);
  88. echo $currentBefore. $userdata->display_name . $currentAfter;
  89. }
  90. elseif ( is_404() )
  91. {
  92. echo $currentBefore . 'Error 404' . $currentAfter;
  93. }
  94. if ( get_query_var('paged') )
  95. echo $currentBefore . __('Page') . ' ' . get_query_var('paged') . $currentAfter;
  96. }

Report this snippet  

You need to login to post a comment.