Title: How run code based on category?
Last modified: August 30, 2016

---

# How run code based on category?

 *  [gotorx7](https://wordpress.org/support/users/gotorx7/)
 * (@gotorx7)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/how-run-code-based-on-category/)
 * Hi All..
 * I have a site which has 4 basic post types, identified by Category.
 * Based on the category I display a different format (EG – Text, Images, Videos
   and Links (to other web-sites).
 * This works great, but I’d like to extend the functionality to the search page
   and individual post displays, which currently show in the default formats.
 * I’ve searched, but haven’t able to come up with anything that helps me, so any
   thoughts would be appreciated please.
 * Cheers,
    Dave

Viewing 1 replies (of 1 total)

 *  [Jay](https://wordpress.org/support/users/phyrax/)
 * (@phyrax)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/how-run-code-based-on-category/#post-6207332)
 * You’ll want to look at the template hierarchy here: [https://developer.wordpress.org/themes/basics/template-hierarchy/](https://developer.wordpress.org/themes/basics/template-hierarchy/)
 * Or if you’re looking for a more linear and less intrusive approach, try the pre_get_posts
   hook with conditionals like `is_search()` and so on.
 * [https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts](https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts)

Viewing 1 replies (of 1 total)

The topic ‘How run code based on category?’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [Jay](https://wordpress.org/support/users/phyrax/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/how-run-code-based-on-category/#post-6207332)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
