WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Insert <div> in PHP code (2 posts)

  1. jvinch
    Member
    Posted 4 years ago #

    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?

  2. jvinch
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.