我想在single中插入以下自定义代码。phpcan I设置了一个条件,即如果存在特定的分类法,则显示并使用此代码,否则不会;
<div id="archivebox"> All courses in<?php echo get_the_term_list($post->ID,\'country\', \' \', \' \', \'\' ) ; ?><br>All courses in<?php echo get_the_term_list($post->ID,\'institute\', \' \', \' \', \'\' ) ; ?><br>All <?php echo get_the_term_list($post->ID,\'subject\', \' \', \' \', \'\', \'\' ) ; ?> courses worldwide<br>All<?php echo get_the_term_list($post->ID,\'qualification\', \' \', \' \', \'\' ) ; ?> courses worldwide<br>Alphabetical List: <?php echo get_the_term_list($post->ID,\'alphabetical\', \' \', \' \', \'\' ) ; ?> worldwide</div>
最合适的回答,由SO网友:Tom J Nowell 整理而成
如果要检查分类是否存在,请使用taxonomy_exists( $taxonomy )
:
<?php
if(taxonomy_exists(\'country\')){
echo \'All courses in\' . get_the_term_list($post->ID,\'country\', \' \', \' \', \'\' );
}
?>
等等。。。
<?php
if( false != get_the_term_list( $post->ID, \'country\' ) ) {
echo \'All courses in\' . get_the_term_list($post->ID,\'country\', \' \', \' \', \'\' );
}
?>