Title: If else statement for category
Last modified: August 21, 2016

---

# If else statement for category

 *  Resolved [krisscross90](https://wordpress.org/support/users/krisscross90/)
 * (@krisscross90)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/if-else-statement-for-category/)
 * I need to create an if else statement (I think) so that when the user is in a
   category that has sub categories, they will not see posts… However when they 
   are in a subcategory with NO child categories, I would like them to see the posts
   then.
 * So far I’ve got it working, however it shows the posts regardless of if there
   are sub categories.
 * To show these sub categories I’ve used this code: [http://pastebin.com/NEZuwCem](http://pastebin.com/NEZuwCem)
 * To show the posts, I’ve just used the wordpress loop: [http://pastebin.com/m0LSpHjt](http://pastebin.com/m0LSpHjt)
 * I just need some help combining the two into an if else statement (I haven’t 
   got much php experience).
 * Many thanks in advance!!
 * [https://wordpress.org/plugins/categories-images/](https://wordpress.org/plugins/categories-images/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Zahlan](https://wordpress.org/support/users/elzahlan/)
 * (@elzahlan)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/if-else-statement-for-category/#post-5075495)
 * Hey
 * All you have to do is to check if the current category has parent or not, something
   like this:
 *     ```
       <?php
       $children = get_categories( array('parent' => get_query_var('cat')) );
       if (!empty($children)) {
       // the current category has children
       }
       else {
       // the current category has no children categories so you can display posts loop goes here
       }
       ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘If else statement for category’ is closed to new replies.

 * ![](https://ps.w.org/categories-images/assets/icon-128x128.png?rev=2256871)
 * [Categories Images](https://wordpress.org/plugins/categories-images/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/categories-images/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/categories-images/)
 * [Active Topics](https://wordpress.org/support/plugin/categories-images/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/categories-images/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/categories-images/reviews/)

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [else](https://wordpress.org/support/topic-tag/else/)
 * [if](https://wordpress.org/support/topic-tag/if/)
 * [subcategory](https://wordpress.org/support/topic-tag/subcategory/)

 * 1 reply
 * 2 participants
 * Last reply from: [Zahlan](https://wordpress.org/support/users/elzahlan/)
 * Last activity: [11 years, 8 months ago](https://wordpress.org/support/topic/if-else-statement-for-category/#post-5075495)
 * Status: resolved