I’m trying to display a list of categories in a PHP enabled text widget. On child category pages I need to get the id of the current category’s parent category and then use that to return a list of all that category’s child categories except the current category.
I tried the following code but it’s not working:
<?php if (is_category( )) {
$thiscat = get_category( get_query_var( 'cat' ) );
$catid = $thiscat->cat_ID;
$parent = $catid->category_parent;
$catlist = get_categories(
array(
'child_of' => $parent,
'orderby' => 'id',
'order' => 'DESC',
'exclude' => $catid,
'hide_empty' => '0'
) );
} ?>
This displays both the parent categories and child categories.