Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. $categories = get_categories(['parent'=>0]);
  2. foreach($categories as $category):
  3. $childCategories = get_categories(['child_of' => $category->cat_ID]);
  4. if(!count($childCategories)){
  5. $link = get_category_link($category->term_id);
  6. $title = $category->name;
  7. printf('<li><a href="%s">%s</a></li>',$link,$title);
  8. }else{
  9. echo '<li>';
  10. printf('<a href="#" class="dropdown-toggle" data-toggle="dropdown"
  11. role="button" aria-haspopup="true" aria-expanded="false">
  12. %s <span class="caret"></span></a>',$category->name);
  13. echo '<ul class="dropdown-menu">';
  14. foreach($childCategories as $child){
  15. $link = get_category_link($child->term_id);
  16. $title = $child->name;
  17. printf('<li><a href="%s">%s</a></li>',$link,$title);
  18. }
  19. echo '</li></ul>';
  20. }
  21. endforeach;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement