を表示します青い帯に第2レベルのメニューを表示します。は、私はここに、このサイト上で働いている唯一の第三レベルのWordpressのメニュー
しかし、私は第3レベルのメニュー(ページの左側)で同じものが必要です。したがって、基本的には、第3レベルのページがあるかどうかを確認するためのコードが必要です。私は2番目のレベルを持っているコードは次のとおりです。だから、
<?php
$menu = wp_nav_menu(
array (
'theme_location' => 'header-menu',
'sub_menu' => true,
'echo' => FALSE,
'fallback_cb' => '__return_false'
)
);
if (! empty ($menu))
{
echo '<div class="sub-nav-container-full">
<div class="container">
<div class="sub-page-menu">';
echo $menu;
echo '</div></div></div>';
}
?>
、私は同様のコードを使用することができると仮定していますが、私は唯一の第三レベルでそれを目指しする方法がわかりませんか?
誰かが助けてくれれば、それは素晴らしいことでしょう! :)
ありがとう、Shaun。
EXTRA - 私の関数はファイルにそれが助け場合、私はまた
// FUNCTION FOR SETTING UP SUB MENU PAGES
// add hook
add_filter('wp_nav_menu_objects', 'my_wp_nav_menu_objects_sub_menu', 10, 2);
// filter_hook function to react on sub_menu flag
function my_wp_nav_menu_objects_sub_menu($sorted_menu_items, $args) {
if (isset($args->sub_menu)) {
$root_id = 0;
// find the current menu item
foreach ($sorted_menu_items as $menu_item) {
if ($menu_item->current) {
// set the root id based on whether the current menu item has a parent or not
$root_id = ($menu_item->menu_item_parent) ? $menu_item->menu_item_parent : $menu_item->ID;
break;
}
}
// find the top level parent
if (! isset($args->direct_parent)) {
$prev_root_id = $root_id;
while ($prev_root_id != 0) {
foreach ($sorted_menu_items as $menu_item) {
if ($menu_item->ID == $prev_root_id) {
$prev_root_id = $menu_item->menu_item_parent;
// don't set the root_id to 0 if we've reached the top of the menu
if ($prev_root_id != 0) $root_id = $menu_item->menu_item_parent;
break;
}
}
}
}
$menu_item_parents = array();
foreach ($sorted_menu_items as $key => $item) {
// init menu_item_parents
if ($item->ID == $root_id) $menu_item_parents[] = $item->ID;
if (in_array($item->menu_item_parent, $menu_item_parents)) {
// part of sub-tree: keep!
$menu_item_parents[] = $item->ID;
} else if (! (isset($args->show_parent) && in_array($item->ID, $menu_item_parents))) {
// not part of sub-tree: away with it!
unset($sorted_menu_items[$key]);
}
}
return $sorted_menu_items;
} else {
return $sorted_menu_items;
}
}
、あなたは第二レベルを推移/表示されたときに第三階層のメニューを表示したいですか? – codiiv
私はそうだと思います - 私は3番目のレベルのメニューを、そのポジション(ページの左側)に1つあり、2番目のレベルのメニューをクリックしたときに誰にでもしたいです....それは意味がありますか? –