Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Menu de categoria wordpress modelo bootstrap
$categories = get_categories(['parent'=>0]);
foreach($categories as $category):
$childCategories = get_categories(['child_of' => $category->cat_ID]);
$link = get_category_link($category->term_id);
$title = $category->name;
printf('<li><a href="%s">%s</a></li>',$link,$title);
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>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.