$cats = get_categories(); | |
$html = ''; | |
if ($cats): | |
$html .= '<ul>'; | |
foreach($cats as $cat){ | |
if($cat->parent == 0): | |
$html .= '<li><a href="'.get_category_link($cat->term_id).'">'.$cat->name.'</a>'; | |
$cats_child = get_categories('child_of=' . $cat->term_id); | |
if ($cats_child): | |
$html .= '<ul class="children">'; | |
foreach($cats_child as $child){ | |
$html .= '<li><a href="'.get_category_link($child->term_id).'">'.$child->name.'</a></li>'; | |
} | |
$html .= '</ul>'; | |
endif; | |
html .= '</li>'; | |
endif; | |
} | |
$html .= '</ul>'; | |
endif; | |
echo $html; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment