简体   繁体   English

将自定义帖子标题添加到wordpress菜单

[英]Adding custom post title to wordpress menu

Excuse my rookieness – this might be a very simple thing to solve for someone with more experience. 请问我的菜鸟–对于有更多经验的人来说,这可能是一件非常简单的事情。 I tried searching the forum but did not find a fitting solution. 我尝试搜索论坛,但没有找到合适的解决方案。

I am trying to make my Wordpress menu add the custom title to a current menu item on a specific post type when that page is active, what would be the best way to do so? 我试图使我的Wordpress菜单在该页面处于活动状态时将自定义标题添加到特定帖子类型的当前菜单项中,这样做的最佳方法是什么?

Menu <--- Original menu item<br>
Menu: Addition <--- When on the custom post type titled "Addition"

Any ideas? 有任何想法吗?

I would start with finding the code in the template ( theme ) where menu is being rendered. 我将从在呈现菜单的模板(主题)中找到代码开始。 You need to look for function that renders navigation menu wp_nav_menu() : https://developer.wordpress.org/reference/functions/wp_nav_menu/ 您需要查找呈现导航菜单的功能wp_nav_menu()https : //developer.wordpress.org/reference/functions/wp_nav_menu/

Depending on how complicated solution you want to choose to pick for checking the post type - I would suggest simple if() statement. 根据您想选择用于检查帖子类型的解决方案的复杂程度,我建议使用简单的if()语句。

To check post type you can use get_post_type() : https://developer.wordpress.org/reference/functions/get_post_type/ 要检查帖子类型,可以使用get_post_type()https : //developer.wordpress.org/reference/functions/get_post_type/

If post type is "Addition" pass argument to wp_nav_menu() to use custom menu prepare for that post type. 如果帖子类型为“添加”,则将参数传递给wp_nav_menu()以使用自定义菜单为该帖子类型做准备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM