在我的自定义WordPress主题的archives.php文件中,我有以下代码:
<div class="page-title">
<?php
if ( is_day() ) :
printf( __( 'Daily Archives: %s', 'sturd' ), '<span>' . get_the_date() . '</span>' );
elseif ( is_month() ) :
printf( __( 'Monthly Archives: %s', 'sturd' ), '<span>' . get_the_date( _x( 'F Y', 'monthly archives date format', 'sturd' ) ) . '</span>' );
elseif ( is_year() ) :
printf( __( 'Yearly Archives: %s', 'sturd' ), '<span>' . get_the_date( _x( 'Y', 'yearly archives date format', 'sturd' ) ) . '</span>' );
else :
_e( 'Archives', 'sturd' );
endif;
?>
</div>
我希望有另一个声明,这样如果这是一个类别页面,它只显示页面 Headers div中的类别 Headers ,而不仅仅是单词Archives(就像它当前那样) .
我希望这张贴在正确的部分 .
提前致谢 .
山姆
1 回答
首先,我建议你使用WP template hierarchy . 我通常会建议使用单独的category.php模板文件来显示类别,并使用single_cat_title()来显示类别名称 .
如果要使用main archive.php模板,可以添加is_category()子句,然后使用single_cat_title()获取名称 .