Imagine i have a URL structure like this: www.domain.com/category/subcategory/
This is my code:
<?php
$args=array(
'child_of' => $cat-id,
'hide_empty' => 0,
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($args);
foreach($categories as $category) {
echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>'; }
?>
When I'm on "www.domain.com/category/" the code correctly displays all children of the category, but when on "www.domain.com/category/subcategory/" the code doesn't display any results because the subcategory doesnt have any children. I need the code to only display the children of the top-level category even when on it's child pages.
How do i accomplish this? TIA.
$cat-id
?