• I would like to be able to vary my titles depending on how many categories the current post has… Say “in the category” if there is only one, but “in the categories” if there are more than one. What would be a good way to do this?

Viewing 1 replies (of 1 total)
  • This will work in The_Loop. Uses the count() function to count the elements in an array.


    <?php $cat=get_the_category(); ?>
    <?php $result = count($cat); ?>
    <?php if ('1'==$result) : ?>
    <?php echo 'Belongs to just one category!'; ?>
    <?php else : ?>
    <?php echo 'Belongs to ' . $result . ' categories!'; ?>
    <?php endif; ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Category count’ is closed to new replies.