Support » Fixing WordPress » Insert <div> in PHP code

  • Resolved jvinch

    (@jvinch)


    This should be an easy one – but I keep getting PHP errors. Maybe someone will have a quick fix for this.

    I have the following code, which is intended to display a taxonomy term description at the bottom of single.php

    <?php $terms = get_the_terms( $post->ID , 'taxonomy-name' );
    if($terms) {
    	foreach( $terms as $term ) {
    		echo $term->description.'<br />';
    	}
    }
    ?>

    Works like a champ. Now I would like to wrap the echoed description in a DIV so I can style it. I’d like to make it part of the PHP query so I won’t see an empty DIV when this post has no terms.

    Any ideas?

Viewing 1 replies (of 1 total)
  • The best questions are the ones you figure out yourself 🙂

    <?php $terms = get_the_terms( $post->ID , 'taxonomy-name' );
    	if($terms) {
    	foreach( $terms as $term ) {
    	echo '<div class="class-name">'
           .$term->description.'<br /></div>';
    		}
    	}
    ?>

    works for me.

Viewing 1 replies (of 1 total)
  • The topic ‘Insert <div> in PHP code’ is closed to new replies.