我不确定您是否希望这样,但是,这可以通过CSS实现。
.crumbs > span > span + span {
margin-left: 1em;
}
.crumbs > span > span + span:before {
content: \'|\'; /* or something else */
*display: inline;
display: inline-block;
margin-left: -1em;
width: 1em;
text-align: center;
}
// EDIT如果您只想使用PHP,那么可以这样做:
function crumbs() {
if ((is_page() && ! is_category()) || is_archive() || is_single() || is_single()) {
$crumbs = \'\';
$crumbs .= \'<div class="crumbs"><span xmlns:v="http://rdf.data-vocabulary.org/#">\';
$crumbs .= \'<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="\'.get_bloginfo(\'url\').\'">Home</a></span>\';
$post_ancestors = get_post_ancestors($post);
if ($post_ancestors) {
$post_ancestors = array_reverse($post_ancestors);
foreach ($post_ancestors as $crumb)
$crumbs .= \'<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="\'.get_permalink($crumb).\'">\'.get_the_title($crumb).\'</a></span>\';
}
if (is_category() || is_single()) {
$category = get_the_category();
$crumbs .= \'<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="\'.get_category_link($category[0]->cat_ID).\'">\'.$category[0]->cat_name.\'</a></span>\';
}
if (!is_category())
$crumbs .= \'<span typeof="v:Breadcrumb"><span class="crumbs-last" property="v:title">\'.get_the_title().\'</span></span>\';
$crumbs .= \'</span></div>\';
$close_crumb = \'</span>\';
$open_crumb = \'<span typeof="v:Breadcrumb">\';
$separator = \'<span class="separator">|</span>\';
echo str_replace($close_crumb.$open_crumb, $close_crumb.$separator.$open_crumb, $crumbs);
}
}
是的,这不好,但这是因为整件事,伊姆霍。