php - 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.
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.
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)
function wpb_custom_new_menu() {
register_nav_menus(
array(
'left-menu' => __( 'C3 Left Menu' ),
)
);
}
add_action( 'init', 'wpb_custom_new_menu' );
解决方案
您可以简单地将菜单放在您希望使用的位置wp_nav_menu
,然后使用 CSS 隐藏除第一个以外的所有菜单项?
推荐阅读
- swift - 在 SwiftUI/Swift 中加载大量静态数据
- authentication - Blazor WebAssembly 第三方身份验证
- typescript - 自动导入不适用于父目录中的相对路径
- python - 问题:无法将 Py 文件转换为 EXE,其中 PyFile 旨在从 Outlook 邮件中获取数据
- c++ - 如何观察 c++ 析构函数破坏基本数据类型?
- javascript - css中的Javascript变量不起作用
- python - Tensorflow:ImportError:DLL load failed while importing _pywrap_tensorflow_internal:找不到指定的模块
- javascript - 用户的详细年龄检查
- javascript - 带有 Vue JS 和 Laravel 的文件上传表单 - 试图显示上传文件的列表?
- java - JsonElement 中的递归键搜索不返回值