Is there a way that I can check using a conditional whether the page is a subcategory of a specific category ?
i.e: on my ‘category.php’ I currently have:
<?php } else if (is_category( 'blog' )) { ?>
This is to render a different view depending which category page the user is on.
Is it possible to do something like ?
<?php } else if (is_sub_category_of( 'blog' )) { ?>
Although very old, I’ve created the perfect solution.
Add this to your
functions.php
file:Then you can use it various ways. For example to change the displaying order of posts in all subcategory pages under a given category:
Enjoy!
Itamar
Old question, but I stumbled on this last night and I had to find an answer for myself.
This is on my
category.php
page:The current subcategory is in
$category
at position0
.This would be harder if “Category You Want” had a parent category and you didn’t know it.
You can see if your current category parent id matches the “blog” category id. If so, your current category is a subcategory of “blog”.
This code will do the functionality you described.