我创建了新的自定义帖子类型,但在面包屑中显示帖子类型名称时遇到问题。
它应该显示“主页»研究»测试研究”,但它显示主页»测试研究”。网站:CLICK
此外,研究(标题)应显示在网站面包屑的左侧:CLICK
在其他页面上,面包屑和标题可以很好地工作。
基本上所有的页面结构都是用一个插件(PMC页面生成器)定义的。因此,如果我不想在插件更新时丢失更改,我就不能真正编辑php文件。
如果需要进一步澄清,请告诉我。顺致敬意,
编辑:来自函数的面包屑代码。php:
/* custom breadcrumb */
function pmc_breadcrumb($title = false) {
global $pmc_data;
$breadcrumb = \'\';
if (!is_home()) {
if($title == false){
$breadcrumb .= \'<a href="\';
$breadcrumb .= home_url();
$breadcrumb .= \'">\';
$breadcrumb .= __(\'Home\', \'pmc-themes\');
$breadcrumb .= "</a> » ";
}
if (is_single()) {
if (is_single()) {
$name = \'\';
if(!get_query_var($pmc_data[\'port_slug\']) && !get_query_var(\'product\')){
$category = get_the_category(); +
$category_id = get_cat_ID($category[0]->cat_name);
$category_link = get_category_link($category_id);
$name = \'<a href="\'. esc_url( $category_link ).\'">\'.$category[0]->cat_name .\'</a>\';
}
else{
$taxonomy = \'portfoliocategory\';
$entrycategory = get_the_term_list( get_the_ID(), $taxonomy, \'\', \',\', \'\' );
$catstring = $entrycategory;
$catidlist = explode(",", $catstring);
$name = $catidlist[0];
}
if($title == false){
$breadcrumb .= $name .\' » <span>\'. get_the_title().\'</span>\';
}
else{
$breadcrumb .= get_the_title();
}
}
} elseif (is_page()) {
$breadcrumb .= \'<span>\'.get_the_title().\'</span>\';
}
elseif(get_query_var(\'portfoliocategory\')){
$term = get_term_by(\'slug\', get_query_var(\'portfoliocategory\'), \'portfoliocategory\'); $name = $term->name;
$breadcrumb .= \'<span>\'.$name.\'</span>\';
}
else if(is_tag()){
$tag = get_query_var(\'tag\');
$tag = str_replace(\'-\',\' \',$tag);
$breadcrumb .= \'<span>\'.$tag.\'</span>\';
}
else if(is_search()){
$breadcrumb .= __(\'Search results for \', \'pmc-themes\') .\'"<span>\'.get_search_query().\'</span>"\';
}
else if(is_category()){
$cat = get_query_var(\'cat\');
$cat = get_category($cat);
$breadcrumb .= \'<span>\'.$cat->name.\'</span>\';
}
else if(is_archive()){
$breadcrumb .= \'<span>\'.__(\'Archive\',\'pmc-themes\').\'</span>\';
}
else{
$breadcrumb .= \'Home\';
}
if(function_exists(\'is_shop\')){
if(is_product() || is_product_category() || is_shop()){
$breadcrumb = \'\';
woocommerce_breadcrumb();
}
}
}
return $breadcrumb ;
}
编辑2:
我打开了Debugger,出现以下错误:“注意:未定义的偏移量:0 in…”和“尝试获取中非对象的属性…”。两者都指向上面的代码,更具体地说是:
f(!get_query_var($pmc_data[\'port_slug\']) && !get_query_var(\'product\')){
$category = get_the_category(); +
$category_id = get_cat_ID($category[0]->cat_name);
$category_link = get_category_link($category_id);
$name = \'<a href="\'. esc_url( $category_link ).\'">\'.$category[0]->cat_name .\'</a>\';
最合适的回答,由SO网友:Martin Peternel 整理而成
所以我发现,我的主题不是为了处理自定义帖子类型而设计的(至少不是通过归档)。解决方案是如下所示编辑代码。更改处插入的注释:
function pmc_breadcrumb($title = false) {
global $pmc_data;
$breadcrumb = \'\';
if (!is_home()) {
if($title == false){
$breadcrumb .= \'<a href="\';
$breadcrumb .= home_url();
$breadcrumb .= \'">\';
$breadcrumb .= __(\'Home\', \'pmc-themes\');
$breadcrumb .= "</a> » ";
}
if (is_single()) {
if (is_single()) {
$name = \'\';
if(!get_query_var($pmc_data[\'port_slug\']) && !get_query_var(\'product\') && !get_query_var(\'study\')/*<-- STUDY ADDED*/){
$category = get_the_category(); +
$category_id = get_cat_ID($category[0]->cat_name);
$category_link = get_category_link($category_id);
$name = \'<a href="\'. esc_url( $category_link ).\'">\'.$category[0]->cat_name .\'</a>\';
}
//ADDED THIS ELSE IF//
else if(!get_query_var($pmc_data[\'port_slug\']) && !get_query_var(\'product\') && get_query_var(\'study\')){
$name = \'<a href="../">\'.__(\'Studies\', \'pmc-themes\').\'</a>\';
}
else{
$taxonomy = \'portfoliocategory\';
$entrycategory = get_the_term_list( get_the_ID(), $taxonomy, \'\', \',\', \'\' );
$catstring = $entrycategory;
$catidlist = explode(",", $catstring);
$name = $catidlist[0];
}
if($title == false){
$breadcrumb .= $name .\' » <span>\'. get_the_title().\'</span>\';
}
else{
$breadcrumb .= get_the_title();
}
}
}
else if (is_page()) {
$breadcrumb .= \'<span>\'.get_the_title().\'</span>\';
}
else if(get_query_var(\'portfoliocategory\')){
$term = get_term_by(\'slug\', get_query_var(\'portfoliocategory\'), \'portfoliocategory\'); $name = $term->name;
$breadcrumb .= \'<span>\'.$name.\'</span>\';
}
else if(is_tag()){
$tag = get_query_var(\'tag\');
$tag = str_replace(\'-\',\' \',$tag);
$breadcrumb .= \'<span>\'.$tag.\'</span>\';
}
/*****I ADDED THIS TO SHOW ON ARCIVE PAGES******/
else if(is_archive()){
$breadcrumb .= \'<span class="span-studies">\'.__(\'Studies\', \'pmc-themes\').\'<span>\';
}
/*****end of my edit******/
else if(is_search()){
$breadcrumb .= __(\'Search results for \', \'pmc-themes\') .\'"<span>\'.get_search_query().\'</span>"\';
}
else if(is_category()){
$cat = get_query_var(\'cat\');
$cat = get_category($cat);
$breadcrumb .= \'<span>\'.$cat->name.\'</span>\';
}
else if(is_archive()){
$breadcrumb .= \'<span>\'.__(\'Archive\',\'pmc-themes\').\'</span>\';
}
else{
$breadcrumb .= \'Home\';
}
if(function_exists(\'is_shop\')){
if(is_product() || is_product_category() || is_shop()){
$breadcrumb = \'\';
woocommerce_breadcrumb();
}
}
}
return $breadcrumb;
}