Show category children, only first children level of curent category/subacategy
-
I need to display first children level of current category (if any), but not children of children.
For example:
Main category (1st level)
– subcategory one (2nd level)
– subcategory two (2nd level)
– some category (3rd level)
– other category (3rd level)
– some category (4th level)When on “Main category (1st level)” I wish to show just:
“subcategory one (2nd level)”
“subcategory two (2nd level)”.When on “subcategory one (2nd level)” I wish to show just:
“some category (3rd level)”
“other category (3rd level)”
…So, I wish just children of current category (not its grandchildren).
This is code I am using, it works, but it shows all children with its sub children…
<?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>'; } ?>
- The topic ‘Show category children, only first children level of curent category/subacategy’ is closed to new replies.