简体   繁体   English

如何从自定义 Wordpress 菜单中获取特定菜单项?

[英]How to get specific menu item from a custom Wordpress menu?

I want to be able to grab a single item from a custom Wordpress menu.我希望能够从自定义 Wordpress 菜单中获取单个项目。

For example, if my menu displays as "Home About Contact", I want to be able to grab just "Home" to generate it elsewhere in the site.例如,如果我的菜单显示为“Home About Contact”,我希望能够仅抓取“Home”以在站点的其他位置生成它。

Here is the code I'm using to get the entire menu in the page.这是我用来获取页面中整个菜单的代码。

<?php
  wp_nav_menu( array( 
  'theme_location' => 'left-menu', 
  'container_class' => 'li' ) ); 
?>

And here is the custom menu code in the functions.php (if you need it)这是函数中的自定义菜单代码。php(如果需要)

function wpb_custom_new_menu() {
register_nav_menus(
array(
  'left-menu' => __( 'C3 Left Menu' ),
)
);
}
add_action( 'init', 'wpb_custom_new_menu' );

You could simply just place the menu in the places you wish using wp_nav_menu , then use CSS to hide all menu items except the first one?您可以简单地将菜单放在您希望使用wp_nav_menu的位置,然后使用 CSS 隐藏除第一个以外的所有菜单项?

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

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