I have this code. But when i enter in subcategory which has no own sub, it disappears. I want if has no subs return parent's subs.
$category->category_parent and $category->parent aren't returning parent cat id.
<div style="margin: 0 0 20px 0;">
<?php $thisCat = get_categories(array('child_of'=>$_GET['cat']));
if(empty($thisCat)){
$thisCat = get_categories(array('parent'=>$_GET['cat']));
}
foreach($thisCat as $cat) { ?>
<div style="margin: 0 25px 0 0; display: inline-block;">
<a style="font-size: 10pt; color: #777; font-weight: normal;" href="/?cat=<?php echo $cat->cat_ID; ?>"><?php echo $cat->name; ?></a><span style="font-size: 7pt; font-weight: bold; background: #f47a6d; padding: 0 4px 0 4px; color: white; border-radius: 1px; margin: -15px 0 0 -5px; position: absolute; text-align: center;"><?php echo $cat->count; ?></span>
</div>
<?php }
?></div>
Example:
Main category
- Sub category 1 (has no sub cats)
- Sub category 2 (has no sub cats)
When i go to "Sub category 1" and "Sub category 2" url i want to show "Main category's" sub categories ("Sub category 1", "Sub category 2") if "Sub Category 1" and "Sub Category 2" has no its own sub categories.