在主题文件functions.php中添加:
function custom_breadcrumbs() {
// 首页
echo '<a href="' . home_url() . '">首页</a>';
if (is_category()) {
// 当前分类
$current_cat = get_queried_object();
// 父级分类
$ancestors = get_ancestors($current_cat->term_id, 'category');
if ($ancestors) {
$ancestors = array_reverse($ancestors);
foreach ($ancestors as $ancestor) {
$cat = get_category($ancestor);
echo ' » <a href="' . get_category_link($ancestor) . '">' . $cat->name . '</a>';
}
}
// 当前分类(无链接)
echo ' » <span class="current-category">' . $current_cat->name . '</span>';
}
}
在分类模板(如category.php)中调用:
<div class="breadcrumb-trail">
<?php custom_breadcrumbs(); ?>
</div>
本文地址: WordPress 主题分类页面面包屑导航
版权声明:如发现本站有涉嫌抄袭侵权/违法违规的内容请联系客服!





