As a purely theory example, this is how I would approach the problem:
$cats = get_categories();
echo '<ul>';
foreach($cats as $cat) {
echo'<li>'.$cat->name;
if($cat->parent != 0) {
$subcats = get_category('child_of=".$cat->cat_ID;
echo "<ul>';
foreach($subcats as $subcat){
echo '<li>'.$subcat->name.'</li>';
}
}
echo '</li>';
}
echo '</ul>';
I don’t expect that to work fully as I coded it there based of this codex entry but I am fairly certain that my theory is correct. I may have the $cat->parent
backwards though…
Related Posts:
- Adding an Arbitrary Link to the Admin Menu?
- How to add ul class on nav
- Show menu item description with line breaks
- Remove/Disable “Automatically add new top-level pages to this menu”
- Which settings/options are saved on a theme-basis and how does this affect theme-switching?
- WordPress Add javascript:void(0); to menu link item?
- Does WordPress create mobile menus automatically?
- Programmatically create and place a nav menu in a theme location?
- Create search form in menu as in Twenty Fourteen theme
- Why is my menu not ordered properly?
- My menu bar dissapeared with autooptimize [closed]
- Cant add menu items with my theme
- How to override the theme home page?
- How to remove menu installed in wp-admin by a theme? [closed]
- Change submenu markup
- Change hyphen/dash for vertical line in menu [closed]
- How should I build a custom menu walker for this setup?
- How to re-arrange the MENU of “Allure Real Estate Theme for Placester” wordpress theme?
- How to override menu markup?
- Want to add different text after each menu item
- Automatically Display Sub Menu
- Menu separator appearing on next line
- Full screen nav menu block with avada theme
- How to hide the menu item created by the theme in WordPress admin panel?
- Creating custom menu with custom themes
- Removing Submenu from Menu
- Efficient wp mobile menu
- How to show submenu of any page in main menu
- adding pages in underscores.me theme
- Structuring Nav Menu and Background Custom page (Help)
- How to work with a custom theme that someone else created before me? (details below)
- Does the Default theme of WordPress like 2016, 2017 and 2019 uses Walker_Nav_Menu Class
- WordPress Menu Navigation links not working
- Menu doesn’t open on mobile
- I can´t make the menu unclickable in an easy way
- WordPress theme editor not showing
- Making my main menu a hamburger menu on all platforms
- menu change after theme change
- menu mobile show up even i in desktop mode in Newspaper Theme
- All custom links suddenly lack href attributes
- Hide menu theme location for certain capabilities?
- Making wordpress menu horizontal [closed]
- Add a Submenu from Another Submenu in a Custom Theme
- wp_nav_menu in 3.7 add name class nav navbar-nav
- how to keep theme background image, menu or site header image while moving site in sub directory?
- Make title bar collapse when scrolling
- How to add or remove borders in navigation menu?
- Customizing Responsive Themes Menu [closed]
- Some informations about the use of statics pages in WordPress
- How can I added the post’s Categories to the site’s top menu (like a page)?
- The menu jumps a few pixels after the website loads
- Is it possible to animate the Twenty Eleven menu? [closed]
- Does Extending Multiple Nav_Menu_Walkers Allow Nested Menus?
- Renaming a WordPress Admin Menu
- Show a WP 3.0 Custom Menu in an HTML Select with Auto-Navigation?
- Simple Navigation Walker – Wrapper-class around first sub-menu
- Add Menu items description via Custom Walker for wp_nav_menu()?
- Wrap description and sub menu in a wrapper
- How to get the post name (slug) from the item ID when traversing the navbar?
- Why is ‘nav_menu_item_args’ filter’s $item argument empty?
- how to get nav menu list through menu name in wordpress
- wp_nav_menu – show children of current menu item only?
- how to assign more permission to wordpress author
- Where would I find Custom menu attributes in the database?
- How to create a Menu based a username
- How to add php to custom link in the nav menu? [closed]
- Remove current class from sub menu items
- Getting menu items like get_pages
- nav_menu not displaying custom menu
- WordPress Menu Prepends URL To My Anchors
- Automatically list top level menu item child pages
- Check if menu_item has children or has parent
- Container class not appearing on navigation menu
- pull non-wp site into content area of wordpress -or- pull wp header into non wp site?
- WordPress template – How to add class to li tag if submenu exist
- display menu as table layout
- Page menu with one image link instead of page title?
- Is there a way to tell menu items to force non-SSL URLs?
- Trouble hiding menu on single page
- change hover color of specific menu link [closed]
- enqueue script during add menu items means before save menu items
- WordPress classes removed when using custom walker
- Show subpages of a category in a custom menu
- How to add a menu that belongs to parent blog to all child-blogs?
- Dropdown primary navigation menu not working
- Understanding with this WordPress code
- Link after WordPress
- Im having trouble centering menu items in footer due to “flexbox”
- When created sub-directory, can we create a new navbar?
- Is it all right to put the whole tag into template_part file?
- Misleading behaviour on Menu & Theme location
- How to build a menu that change style over a section
- How i can get current menu id with multiple occurrence
- Links in new menu don’t work
- Next/previous a-like single navigation
- How to create a menu super voice in WP?
- How to set up suhosin.ini for unlimited menus
- How To Conditionally Change Menu In Same Theme Location
- Add menu to CMS page
- Not even able to Log in [closed]