hangar-wp-theme/library/breadcrumb.php

57 lines
3.7 KiB
PHP
Raw Normal View History

2021-02-18 14:09:56 +01:00
<?php
function truncate_text($text, $nbrChar, $append='...') {
if(strlen($text) > $nbrChar) {
$text = substr($text, 0, $nbrChar);
$text .= $append;
}
return $text;
}
function wp_breadcrumb() {
global $cat,$s,$post,$wp_locale;
if ( get_the_category() ) $category = get_the_category();
if ( is_tag() ) $tag = get_term($tag_ID, 'post_tag', OBJECT, 'display');
if ( is_author() ) $userdata = get_userdata($author);
?><div id="breadcrumb"><ul><li class="start"><a href="<?php bloginfo('url'); ?>/" title="<?php bloginfo('name'); ?>"><?php echo __('Home'); ?></a></li><?php
if ( have_posts() ) :
// Display breadcrumb for category and sub-category archive
if ( is_category() ) {?><li><?php echo substr(get_category_parents($cat,true,'</li><li>'),0,-9); ?></li><?php }
// Display breadcrumb for calendar archive
elseif ( is_day() ) {?><li><a href="<?php echo get_year_link(get_the_time('Y')); ?>"><?php the_time('Y'); ?></a></li><li><a href="<?php echo get_month_link(get_the_time('Y'),get_the_time('m')); ?>"><?php the_time('F'); ?></a></li><li><a href="<?php echo get_day_link(get_the_time('Y'),get_the_time('m'),get_the_time('d')); ?>"><?php the_time('d'); ?></a></li><?php }
elseif ( is_month() ) {?><li><a href="<?php echo get_year_link(get_the_time('Y')); ?>"><?php the_time('Y'); ?></a></li><li><a href="<?php echo get_month_link(get_the_time('Y'),get_the_time('m')); ?>"><?php the_time('F'); ?></a></li><?php }
elseif ( is_year() ) {?><li><a href="<?php echo get_year_link(get_the_time('Y')); ?>"><?php the_time('Y'); ?></a></li><?php }
// Display breadcrumb for single post and attachments
elseif ( is_single() ) {?>
<li><?php echo substr(get_category_parents($category[0]->cat_ID,true,'</li><li>'),0,-9); ?></li>
<?php if($post->post_parent ) {?>
<li><a href="<?php echo get_permalink($post->post_parent); ?>"><?php echo get_the_title($post->post_parent); ?></a></li>
<?php } ?>
<li><?php echo truncate_text(the_title('','',false),20); ?></li>
<?php }
// Display breadcrumb for pages
elseif ( is_page() ) {if ( $post->post_parent ) {?><li><a href="<?php echo get_permalink($post->post_parent); ?>"><?php echo get_the_title($post->post_parent); ?></a></li><?php } ?><li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li><?php }
// Display breadcrumb for search result page
elseif ( is_search() ) {?><li><a href="<?php echo clean_url( get_pagenum_link() ); ?>" title="<?php echo __('Search result for') . ' ' . wp_specialchars(get_query_var('s')); ?>"><?php echo __('Search result for') . ' ' . wp_specialchars(get_query_var('s')); ?></a></li><?php }
// Display breadcrumb for tag archive
elseif ( is_tag() ) {?><li><a href="<?php echo clean_url( get_pagenum_link() ); ?>" title="<?php echo __('Archive for tag') . ' ' . $tag->name; ?>"><?php echo __('Archive for tag') . ' ' . $tag->name; ?></a></li><?php }
// Display breadcrumb for author archive
elseif ( is_author() ) {?><li><a href="<?php echo clean_url( get_pagenum_link() ); ?>" title="<?php echo __('Article posted by') . ' ' . $userdata->display_name; ?>"><?php echo __('Article posted by') . ' ' . $userdata->display_name; ?></a></li><?php }
// Display breadcrumb for page which got split
if ( get_query_var('page') ) {?><li><a href="<?php get_permalink(); ?>" title="<?php echo __('Part'); ?> <?php echo get_query_var('page'); ?>"><?php echo __('Part'); ?> <?php echo get_query_var('page'); ?></a></li><?php }
// Display breadcrumb for paged archives
if ( get_query_var('paged') ) {?><li><a href="<?php get_permalink(); ?>" title="<?php echo __('Page'); ?> <?php echo get_query_var('paged'); ?>"><?php echo __('Page'); ?> <?php echo get_query_var('paged'); ?></a></li><?php }
endif;
?></ul>
</div>
<?php
}
?>