Title: Category count
Last modified: August 18, 2016

---

# Category count

 *  [delaque](https://wordpress.org/support/users/delaque/)
 * (@delaque)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/category-count/)
 * 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)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [20 years, 3 months ago](https://wordpress.org/support/topic/category-count/#post-337423)
 * This will work in [The_Loop](http://codex.wordpress.org/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.

## Tags

 * [count](https://wordpress.org/support/topic-tag/count/)
 * [pretty](https://wordpress.org/support/topic-tag/pretty/)

 * 1 reply
 * 2 participants
 * Last reply from: [MichaelH](https://wordpress.org/support/users/michaelh/)
 * Last activity: [20 years, 3 months ago](https://wordpress.org/support/topic/category-count/#post-337423)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
