简体   繁体   中英

Detect if category is a parent - on wordpress template category.php

I have created a category.php template in my theme and would like some code to detect if the category being viewed is a parent or not. If it is then I want to set a variable to one value, if it isn't I want to set it to another value. Is this possible?

Try this, and assign the values in it.

<?php $this_category = get_category($cat); ?>

<?php if ($this_category->category_parent == 0) { ?>
    <!-- If Parent -->
<?php } else { ?>
    <!-- Else This -->
<?php } ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM