wordpress面包屑导航 纯代码实现

网上找了很多纯代码实现的wordpress面包屑导航,结果没有一个满意的,特别是分类目录这里,面包面包屑导航不能实现分类层级展示出来,经过我的研究,下面分享一份我整改后的PHP代码,如下:

 

1、category.php 面包屑导航位置代码:

  <nav id="mbx">当前位置:<a href="<?php bloginfo('url'); ?>">
 首页
  </a> &gt;   <?php
if( is_single() ){
$categorys = get_the_category();
$category = $categorys[0];
echo( get_category_parents($category->term_id,true,' &gt; ') );
echo ' 正文';
} elseif ( is_page() ){
the_title();
} elseif ( is_category() ){
 $delimiter = ' &gt; ';
global $wp_query;
            $cat_obj = $wp_query->get_queried_object();
            $thisCat = $cat_obj->term_id;
            $thisCat = get_category($thisCat);
            $parentCat = get_category($thisCat->parent);
            if ($thisCat->parent != 0) {
                echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
            }
            echo $before  . single_cat_title('', false) . $after;
} elseif ( is_tag() ){
single_tag_title();
} elseif ( is_day() ){
the_time('Y年Fj日');
} elseif ( is_month() ){
the_time('Y年F');
} elseif ( is_year() ){
the_time('Y年');
} elseif ( is_search() ){
echo $s.' 的搜索结果';
}
?></nav>

 

2、最终实现的效果:

wordpress面包屑导航

    A+
所属分类:WordPress
发布日期:2024年08月03日 09:25:26
最后更新时间:2024-08-03 09:32:30
付杰

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: