在下拉菜单中显示剩余的 WordPress 类别
我的主题顶部的水平类别导航栏的空间有限,我需要限制此栏上显示的类别数量,并告诉 WordPress 将“更多..”作为下拉菜单链接放在列表末尾,以便用户将鼠标光标悬停在该类别上即可查看其他类别,如屏幕截图所示。
我怎样才能做到这一点?
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 other categories as shown in screenshot.
How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
取决于您使用什么功能来格式化导航菜单。它可能是
wp_list_categories()
这可能不是您的情况的最佳选择。正如 @Andre 在他的回答中提到的,您可能想要使用自 WordPress 3 以来可用的导航菜单,但如果您需要坚持类别,请尝试get_categories()
,它将以非-格式化的方式。这将使您能够以任何您想要的方式循环遍历它们,包括一个计数器来限制一般输出,然后循环遍历“更多”子菜单下的其余部分。参考:get_categories
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, tryget_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
我猜你使用的是 WordPress 3+ 版本。
这可能不是最简洁的方法,但应该可行:
但是,我不确定您是否希望“更多..”菜单项成为链接页面/类别。所有这些都是可能的,只需添加类别/页面而不是“自定义链接”。
希望这个解决方法可以解决您的问题。
I guess you are using wordpress version 3+.
This is probably not the cleanest way but should work:
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.