Want to check if a category has a parent category in WordPress? Use following code in your theme’s functions.php file OR in site specific plugin.
1 2 3 4 5 6 7 |
function category_has_parent($catid){ $category = get_category($catid); if ($category->category_parent > 0){ return true; } return false; } |
Now call the function from template like below example:
1 2 3 |
if(category_has_parent($tid)) { // it has a parent } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.