I want to insert following custom code in single.php
can I set condition that if specific taxonomy exist then show and work this code otherwise not;

<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>

2 Answers
2

If you want to check for the existence of a taxonomy, use taxonomy_exists( $taxonomy ):

<?php
if(taxonomy_exists('country')){
     echo 'All courses in' . get_the_term_list($post->ID,'country', ' ', ' ', '' );
}
?>

etc…

Edit

If, instead of checking for the existence of a taxonomy, you want to check if the current post belongs to a taxonomy, use get_the_term_list( $post->ID, $taxonomy ):

<?php
if( false != get_the_term_list( $post->ID, 'country' ) ) {
     echo 'All courses in' . get_the_term_list($post->ID,'country', ' ', ' ', '' );
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *