您可以使用Conditional Tag in_category()
在循环内:
if( in_category( \'events\' ) ):
// output stuff for events category post
else:
// not in events category
endif;
单篇文章的另一个选择是
load a different template with a filter 根据类别:
function wpa8176_category_single_template( $template = \'\' ){
$categories = get_the_category();
foreach( $categories as $cat ):
if( \'events\' == $cat->name ):
$template = locate_template( array( "events-single.php", $template ), false );
endif;
endforeach;
return $template;
}
add_filter( \'single_template\', \'wpa8176_category_single_template\' );