Show remaining wordpress categories in drop down menu
I have limited space for horizontal category navigation bar on top of my theme and I need to limit number of categories shown on this bar and tell WordPress put "More.." as a drop down menu link at the end of the list to let users hover their mouse cursors on that to see othe开发者_StackOverflow中文版r categories as shown in screenshot.
How can I do that?
Depends on what function you're using to format the navigation menu. It's probably wp_list_categories()
which might not be the best choice in your case. As @Andre mentioned in his answer, you might want to go with navigation menus available since WordPress 3, but if you need to stick to categories, try get_categories()
which will return the categories in a non-formatted way. This will enable you to loop through them in any way that you want, include a counter to limit the general output, and then loop through the rest under the More submenu.
Reference: get_categories
I guess you are using wordpress version 3+.
This is probably not the cleanest way but should work:
- Register a custom menu to your template. Watch the 'depth' parameter (because you want the second level)
- Go to 'Appearance - Menus'
- Create a Custom Menu
- Create a 'Custom Link' called 'More...'
- add the 'More...' Link with the other categories as sub-categories to the menu.
- write your CSS code to only display the second level on hover.
However, I'm not sure if you want the 'More..' menu item to be a linkpage/category. All of that is possible, just add the category/page instead of the 'Custom Link'.
Hope this workaround can solve your problem.
精彩评论