Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $categories = get_categories(['parent'=>0]);
- foreach($categories as $category):
- $childCategories = get_categories(['child_of' => $category->cat_ID]);
- if(!count($childCategories)){
- $link = get_category_link($category->term_id);
- $title = $category->name;
- printf('<li><a href="%s">%s</a></li>',$link,$title);
- }else{
- echo '<li>';
- printf('<a href="#" class="dropdown-toggle" data-toggle="dropdown"
- role="button" aria-haspopup="true" aria-expanded="false">
- %s <span class="caret"></span></a>',$category->name);
- echo '<ul class="dropdown-menu">';
- foreach($childCategories as $child){
- $link = get_category_link($child->term_id);
- $title = $child->name;
- printf('<li><a href="%s">%s</a></li>',$link,$title);
- }
- echo '</li></ul>';
- }
- endforeach;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement