简体   繁体   English

在WordPress中添加文本和变量wp_nav_menu $ menu_class

[英]Add both text and variable in WordPress wp_nav_menu $menu_class

I am generating a menu in WordPress using wp_nav_menu() function and I want to add both text and variable into the 'menu_class' property. 我正在使用wp_nav_menu()函数在WordPress中生成菜单,我想将文本和变量都添加到'menu_class'属性中。

Now this is how I do it: 现在这就是我的方法:

 `'menu_class'      => 'text' . $variable,`

However no class is shown when I use this method (no error/warnings as well). 但是,当我使用此方法时,没有显示任何类(也没有错误/警告)。

I want to know how to add the text "text" and the variable "$variable" into 'menu_class' property? 我想知道如何将文本“ text”和变量“ $ variable”添加到“ menu_class”属性中吗?

Thanks 谢谢

here's the documentation for wp_nav_menu() . 这是wp_nav_menu()的文档。 It says for menu_class... 它说的是menu_class ...

the class that is applied to the ul element which encloses the menu items. 应用于包含菜单项的ul元素的类。 Multiple classes can be separated with spaces. 多个类可以用空格分隔。 Formerly known as $wrap_class 原名$ wrap_class

so try adding a space? 所以尝试添加一个空格?

'menu_class'      => 'text' . ' ' . $variable,

or just 要不就

'menu_class'      => 'text ' . $variable,

this is apparenlty a good tutorial: IMPROVE YOUR WORDPRESS NAVIGATION MENU OUTPUT 这显然是一个很好的教程: 改善您的WORDPRESS导航菜单输出


This SO post deals with code that deals with two menu classes: php code optimization for wordpress nav menu . 这样的SO帖子处理涉及两个菜单类的代码用于wordpress nav menu的php代码优化 Are you sure that your variable has a value? 您确定变量具有值吗? I work with PHP all the time and that's definitely how you do string concatenation. 我一直在使用PHP,这绝对是您进行字符串连接的方式。

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

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