The code in this tutorial enables you to hook in a list of terms and display them as menu items in a custom nav menu.
You can dynamically display all terms for a registered taxonomy or all terms for 1 or more custom post types regardless of whether the CPT and/or taxonomy terms are registered using code in your theme or a plugin.
The code is tested using the AgentPress Listings plugin and the Genesis Portfolio Pro plugin which both register CPT’s and include support for creating custom taxonomy terms.
Here’s a screenshot showing the terms listed in a nav menu hooked after the header:
And here’s the demo video showing how the menu dynamically adds or removes terms as menu item links as you add or remove them.
The demo video shows how you can hook in a custom menu which dynamically adds each custom taxonomy term ( with Count ) to a new menu item. When new terms are created, they are dynamically added as a new menu item in the menu.
There’s 2 code snippets in this tutorial which enable you to:
- Use the code with any taxonomy types generated by a theme or plugin.
- Use the code with 1 or more custom post types generated by a theme or plugin.
- Display each term with or without a link or count.
- Style the menu like the default genesis nav menus or differently.
- Hook the terms menu using any Genesis or WordPress hook location
- Customize the functionality of the code using any of the WP_Term_Query parameters
The following code snippets for logged in members have been written and tested based on this question from a member of the StudioPress community forums:
How to show number of listings for each term in menu?
I am using AgentPress Pro theme and want to create a custom menu for specific Terms. My question is how to show number of listings for each term in the menu? Is there any already hacks there?