Show wordpress subcategories only
13,381
This code should help you:
<ul>
<?php
$cats = get_the_category();
$mycat = $cats->cat_ID;
wp_list_categories('orderby=id&child_of='.$mycat);
?>
</ul>
OR
<?php
if (is_category()) {
$cat = get_query_var('cat');
$this_category = get_category($cat);
$this_category = wp_list_categories('hide_empty=0&hierarchical=true&orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID."&echo=0");
if($this_category !='<li>No categories</li>')
{
echo '<ul>'.$this_category.'</ul>';
}
}
?>
Let me know please.
Good luck! :)
Author by
user1138383
Updated on June 17, 2022Comments
-
user1138383 almost 2 years
I have 7 Categories (parents), and every category has 15 sub-categories.
When I select some category (parent), I want to display only sub-categories (children) of that particular parent category (parent).
After I click on sub-category (child) then it should display its posts only.
I have a
fron_page.php
andcategory.php
.How can I write this to first show sub-categories separately, then post of that sub-category separately in new file, which user want to see.