• Hi,

    I have a loop that when if nothing is returned a message should come up saying something like “no content here” but can’t seem to figure out how to make that happen. It’s probably extremely simple, but I’ve spent a good amount of time with no success. Anyone with some insight on this would be a big help.

    <?php foreach((get_the_category()) as $childcat) {
    if (cat_is_ancestor_of(207, $childcat)) {
    echo '<div class="Cat Emotion">';
    echo 'cat_ID).'">';
    echo $childcat->cat_name . '
    ';
    echo '</div>';
    }
    } ?>

    So here’s some details (just in case it helps). This loop returns all the categories for the current post you’re on, then takes the ones that are children of “207” and displays relative info from those child cats. When nothing is a child of “207” I would like to have a simple message display. But, nothing I do seems to make that happen, hehe.

Viewing 1 replies (of 1 total)
  • Try counting the number of categories found:

    <?php
       $found = 0;
       foreach((get_the_category()) as $childcat) {
          if (cat_is_ancestor_of(207, $childcat)) {
             ++$found;
             echo '<div class="Cat Emotion">';
             echo 'cat_ID).'">';
             echo $childcat->cat_name . ' ';
             echo '</div>';
          }
       }
       if (!$found) {
          echo "Nothing found";
       }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘If No Values In Category Loop Echo Something’ is closed to new replies.