Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Good morning

Display Subcategories on Category Pages in WordPress

SnippetsWordPress

About a 1 minute read

"Individually, we are one drop. Together, we are an ocean."

Ryunosuke Satoro


1
2
3
4
5
6
7
8
9
10
11
12
13
 <?php
    if (is_category()) {$this_category = get_category($cat); }

    if($this_category->category_parent)
        $this_category = wp_list_categories('orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->category_parent."&echo=0");
    else
        $this_category = wp_list_categories('orderby=id&depth=1&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID."&echo=0");
   
    if ($this_category) { ?>
        <ul>
            <?php echo $this_category; ?>
        </ul>
<?php } ?>