Title: category functions
Last modified: August 18, 2016

---

# category functions

 *  [RobotHero](https://wordpress.org/support/users/robothero/)
 * (@robothero)
 * [22 years ago](https://wordpress.org/support/topic/category-functions/)
 * I want to apply a different layout to one category of post. I’ve been looking
   at the category functions, and I’m not sure what’s the easiest way to test, “
   Is this post of category X?”
    the_category_ID is always returning 0, so I don’t
   know if I’m using it wrong. `<?php the_category_ID() ?>` always prints 0 Unless
   someone suggests a better way, I’m going to try writing my own function for this,
   which will use get_the_category() and test to see if a certain category is returned
   in the results.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [charle97](https://wordpress.org/support/users/charle97/)
 * (@charle97)
 * [22 years ago](https://wordpress.org/support/topic/category-functions/#post-47298)
 * write your own function to pull category ids. the_category_id function is trying
   to pull a post’s category id from a field that is apparently deprecated.
 *  Thread Starter [RobotHero](https://wordpress.org/support/users/robothero/)
 * (@robothero)
 * [22 years ago](https://wordpress.org/support/topic/category-functions/#post-47299)
 * Okay. I added this to myhacks.
    `function the_category_IDs() { $IDs = array();
   $categories=get_the_category(); for ($i=0;$i<count($categories);$i++) { $IDs[]
   = $categories[$i]->category_id; }; return $IDs; } And then anywhere I want to
   test to see if a post is in a category, I just use if (in_array(X,the_category_IDs()))
   where X is the category ID I’m testing for.
 *  [pIng](https://wordpress.org/support/users/ping/)
 * (@ping)
 * [22 years ago](https://wordpress.org/support/topic/category-functions/#post-47824)
 * Instead of using complex hack code, I chose to simply search the query string
   for the category number, then I’ve inserted it inline where needed to modify 
   image or css tags. I’m no PHP guy, but this works great for me and it’s one line
   of code:
    <?php echo($cat); ?>

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘category functions’ is closed to new replies.

 * 3 replies
 * 3 participants
 * Last reply from: [pIng](https://wordpress.org/support/users/ping/)
 * Last activity: [22 years ago](https://wordpress.org/support/topic/category-functions/#post-47824)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
