我已经成功地在WordPress中创建了一个自定义分类法,并创建了一张页面,其中列出了指定分类法下的所有帖子,文件名为taxonomy.php
。它可以工作,但有些php不打印任何文本。该页面似乎在打开错误报告的情况下大量出现了一些php错误:
Notice: Undefined variable: term_name in WEBSITE_ROOT/themes/starkers/taxonomy.php on line 24
变量为$term_name
。这是我的taxonomy.php
页面中的代码。我遵循了本教程。我觉得我很好地遵循了教程。
<?php
get_header(); ?>
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
<h1><?php
printf( __( 'Posts classified under: %s', 'starkers' ), '<span>' . $term_name . '</span>' );
?></h1>
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo '' . $category_description . '';
get_template_part( 'loop', 'category' );
?>
<?php get_footer(); ?>
基本上,它不会在"分类在以下的帖子"之后打印分类名称
我试着摆弄代码,但没有成功。如果有帮助的话,下面是我用于functions.php
注册分类法的代码:
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy(
'quotees',
'post',
array(
'hierarchical' => false,
'label' => 'quotees',
'query_var' => true,
'public' => true,
'rewrite' => true
)
);
}
如果您查看注释,显然$term_name
应该是$term->name
。事实上,大多数$term_blahs
应该是$term->blah
。