Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从wordpress菜单中获取特定项_Php_Wordpress - Fatal编程技术网

Php 从wordpress菜单中获取特定项

Php 从wordpress菜单中获取特定项,php,wordpress,Php,Wordpress,在尝试构建2个链接菜单时,让我们假设菜单选项中的层次结构如下所示 - A -- B -- C -- D -- D1 -- D2 - A1 第一个菜单我希望它是固定的,所以我拿了它 “深度”=>1 第二个菜单必须根据第一个菜单进行更改,就像如果我按A键,它将只显示B、C和D 当我按下B时,它仍然必须打开为B,C,D,如果我按下D1的话。我想我们明白了它应该如何工作。 当我试图构建它时,我只允许她在您从主菜单(如A或A1)中进行选择时才能获取菜单。 但当你在深度菜单中选择更深的时

在尝试构建2个链接菜单时,让我们假设菜单选项中的层次结构如下所示

- A
 -- B
 -- C
 -- D
   -- D1
   -- D2
- A1
第一个菜单我希望它是固定的,所以我拿了它 “深度”=>1

第二个菜单必须根据第一个菜单进行更改,就像如果我按A键,它将只显示B、C和D 当我按下B时,它仍然必须打开为B,C,D,如果我按下D1的话。我想我们明白了它应该如何工作。 当我试图构建它时,我只允许她在您从主菜单(如A或A1)中进行选择时才能获取菜单。 但当你在深度菜单中选择更深的时候,它会显示hi的孩子们。比如,如果我选择D,子菜单就会变成D1和D2,我不想要它, 我试着检查菜单的深度,或者得到任何可以帮助我进行分类的东西,但是我找不到任何东西

下面是一些代码: 职能:

function submenu_get_children_ids( $id, $items ) {

    $ids = wp_filter_object_list( $items, array( 'menu_item_parent' => $id ), 'and', 'ID' );

    foreach ( $ids as $id ) {

        $ids = array_merge( $ids, submenu_get_children_ids( $id, $items ) );
    }

    return $ids;
}
获取菜单:

$menu = wp_nav_menu(array(
    'container' => false,                           // remove nav container
    'container_class' => 'right_menu',                 // class of container (should you choose to use it)
    'menu' => __( 'top_main_nav', 'bonestheme' ),  // nav name
    'menu_class' => 'main_bar_menu '.$lang.'',               // adding custom nav class
    'theme_location' => 'main-nav',                 // where it's located in the theme
    'before' => '',                                 // before the menu
    'after' => '',                                  // after the menu
    'link_before' => '',                            // before each link
    'link_after' => '',                             // after each link
    'depth' => 1,                                   // limit the depth of the nav
    'fallback_cb' => ''                             // fallback function (if there is one)
)); 


$current_page = 0;
// check if the current page has a menu.

foreach(wp_get_nav_menu_items('top_main_nav') as $pagec) {
    if(get_the_title() == $pagec->title) {
        $current_page = $pagec->title;
    }
}

if($current_page === 0) {
    $current_page = "Home";

}


$args = array(
    'container' => false,
    'container_class' => 'main_bar_menu',
    'menu'    => 'top_main_nav',
    'menu_class' => 'main_bar_menu',
    'submenu' => $current_page,
);
wp_nav_menu( $args ); 
我现在正试图在大约两天内找到一个解决方案:\如果有人能给我提供指导,我将非常感激

非常感谢