在主题文件functions.php中添加:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 ' &raquo; <a href="' . get_category_link($ancestor) . '">' . $cat->name . '</a>';
}
}

// 当前分类(无链接)
echo ' &raquo; <span class="current-category">' . $current_cat->name . '</span>';
}
}

在分类模板(如category.php)中调用:

1
2
3
4
<div class="breadcrumb-trail">
<?php custom_breadcrumbs(); ?>
</div>