我有一个自定义的帖子类型。看起来面包屑为插入的父页面(不存在)提供了额外的空间。你可以在我所附的图片中看到这一点。
导致这个额外的、不存在的父级的自定义帖子类型发生了什么?
以下是我的自定义页面类型:
add_action( \'init\', \'register_cpt_result\' );
function register_cpt_result() {
$labels = array(
\'name\' => _x( \'Case Results\', \'result\' ),
\'singular_name\' => _x( \'Result\', \'result\' ),
\'add_new\' => _x( \'Add New\', \'result\' ),
\'add_new_item\' => _x( \'Add New Result\', \'result\' ),
\'edit_item\' => _x( \'Edit Result\', \'result\' ),
\'new_item\' => _x( \'New Result\', \'result\' ),
\'view_item\' => _x( \'View Result\', \'result\' ),
\'search_items\' => _x( \'Search Case Results\', \'result\' ),
\'not_found\' => _x( \'No case results found\', \'result\' ),
\'not_found_in_trash\' => _x( \'No case results found in Trash\', \'result\' ),
\'parent_item_colon\' => _x( \'Parent Result:\', \'result\' ),
\'menu_name\' => _x( \'Case Results\', \'result\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'description\' => \'My firm\\\'s case results\',
\'supports\' => array( \'title\', \'editor\', \'excerpt\' ),
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => true,
\'has_archive\' => true,
\'query_var\' => true,
\'can_export\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\'
);
register_post_type( \'result\', $args );
}
以下是我的面包屑功能:
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);
}
}