WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] if category description = empty ... (2 posts)

  1. mores
    Member
    Posted 5 years ago #

    <?php
    foreach (get_the_category() as $cat) {
    	$parent = get_category($cat->category_parent);
    	$parent_name = $parent->cat_name;
    	$parent_description = $parent->description;
    	echo '<div id="content_headline"><h1>'.$parent_name.'</h1></div>';
    	if (strlen($parent_description)>0) {
    		echo '<div id="content_main">'.$parent_description.'</div>';
    	}
    }
    ?>

    I use this code to display the parent cat and it's description.
    The bit to check if there actually is a description does no work ... I get the DIVs no matter what.
    Any ideas?

  2. Syntax Terror
    Member
    Posted 4 years ago #

    Mores,
    The WordPress Codex mentions: "Note: if there is no category description, the function returns a br tag"

    Perhaps you should compare if the value held is not empty, but holding this
    ?

    Good luck!

Topic Closed

This topic has been closed to new replies.

About this Topic