Title: Count categories within loop?
Last modified: August 19, 2016

---

# Count categories within loop?

 *  [shrthnd](https://wordpress.org/support/users/shrthnd/)
 * (@shrthnd)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/count-categories-within-loop/)
 * I need to switch class/text-size of the list of categories – the more categories
   smaller the text needs to be.
 * What I am trying to do is set up a conditional statement depending on how many
   categories are assigned to a post.
 * What is the best/easiest/most effective way to count() the number of categories
   returned by the_category()?

Viewing 1 replies (of 1 total)

 *  [jon](https://wordpress.org/support/users/adiant/)
 * (@adiant)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/count-categories-within-loop/#post-1178020)
 * Although it can be done with the_category, I’d be more inclined to use: `count(
   get_the_category())`
 * But be sure to read:
    [http://codex.wordpress.org/Function_Reference/get_the_category](http://codex.wordpress.org/Function_Reference/get_the_category)
 * The use of get_the_category depends on whether or not you are inside the WordPress
   loop when you call it. It requires a parameter if you are outside The Loop.

Viewing 1 replies (of 1 total)

The topic ‘Count categories within loop?’ is closed to new replies.

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [the_category](https://wordpress.org/support/topic-tag/the_category/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [jon](https://wordpress.org/support/users/adiant/)
 * Last activity: [16 years, 10 months ago](https://wordpress.org/support/topic/count-categories-within-loop/#post-1178020)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
