在wordpress主题的“functions.php”文件里粘贴如下函数代码:
function tx_breadcrumbs(){
if (!is_home()) {
echo '<a href="' . get_settings('home') . '" title="回到首页">首页</a>';
if (is_category()) {
$cat_ID = get_query_var('cat');
echo " > " . get_category_parents($cat_ID, TRUE, " > ");
} elseif (is_single()) {
$category = get_the_category();
$category_id = $category[0]->term_id;
echo ' > ' . get_category_parents($category_id, TRUE, " > ");
echo the_title();
} else {
echo " > ";
echo wp_title('', 0);
}
}
}
if (!is_home()) {
echo '<a href="' . get_settings('home') . '" title="回到首页">首页</a>';
if (is_category()) {
$cat_ID = get_query_var('cat');
echo " > " . get_category_parents($cat_ID, TRUE, " > ");
} elseif (is_single()) {
$category = get_the_category();
$category_id = $category[0]->term_id;
echo ' > ' . get_category_parents($category_id, TRUE, " > ");
echo the_title();
} else {
echo " > ";
echo wp_title('', 0);
}
}
}
然后在需要引用的地方写上
<?php echo tx_breadcrumbs(); ?>
即可显示。