3级Wordpress导航问题


3 Level Wordpress navigation problems

我还在摆弄这个愚蠢的导航菜单。这个想法是,当你第一次去页面的顶层页面列出,当其中一个被点击二级菜单出现在它下面与所有选定的页面子页面,当其中一个页面被点击所有的第三级页面从选定的第二级页面显示在第二级页面下面。

我试过用各种方法来完成这个,我甚至试过做一个会话存储来记住一些部分,但是我就是不能想出一个好的解决方案。

到目前为止我所做的是:

<?php
wp_nav_menu(array(
    'sort_column' => 'menu_order',
    'theme_location' => 'primary-menu'
));// Prints the primary top level menu
$level = count($post->ancestors);
echo $level;// Just for testing purposes
if ($post->post_parent){
    $children = wp_list_pages("title_li=&child_of=" . $post->post_parent . "&echo=0&depth=1");
     $grandchildren = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
}
else{
    $children = wp_list_pages("title_li=&child_of=" . $post->ID . "&echo=0&depth=1");
}
if ($children) {
    echo $children;
}
if ($grandchildren){
    echo $grandchildren; 
}
?>

这是我遇到的问题。它的工作方式是单向的,所以如果我点击第一层,第二层出现,如果我点击第二层,第三层出现,但当我点击第三层,第二层消失。

我快疯了!我花了一天的时间来阅读get_post get_children等等等等。

谢谢,C

这是我的解决方案与子菜单和子菜单的子菜单....等。

我这样称呼菜单:

 <?php $defaults = array(
'theme_location'  => '',
'menu'            => 'TopMenu', 
'container'       => 'ul', 
'container_class' => 'topmenu-{topmenu slug}-container', 
'container_id'    => 'topmenu',
'menu_class'      => 'topmenu', 
'menu_id'         => 'topmenu-{topmenu slug}[-{increment}]',
'echo'            => true,
'fallback_cb'     => 'wp_page_menu',
'before'          => '',
'after'           => '',
'link_before'     => '',
'link_after'      => '',
'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth'           => 0,
'walker'          => ''

);?>

这个菜单使用了一个简单的topmenu类。好的,这是你可以自定义的css。

.topmenu{
    border:none;
    border:0px;
    margin:0px;
    padding:0px 0px 0px 10px;
    font-family:Arial, serif;
    font-size:10px;
    list-style-type:none;
    }
.topmenu ul{
    height:20px;
    list-style:none;
    margin:0;
    padding:0;
     }
.topmenu li{
    float:left;
    padding:0px;
    list-style-type:none;
    }
.topmenu li a{
    background-color:#000000;
    color:#6699CC;
    display:block;
    line-height:20px;
    margin:0px;
    padding:0px 10px;
    text-align:center;
    text-transform:uppercase;
    letter-spacing:-1px;
    text-decoration:none;
    list-style-type:none;
    border-right:1px solid #666666;
    }
    .topmenu li:first-child a { border-left: none; }
    .topmenu li:last-child a{ 
    padding-right:0;
    border-right:none;
    }
    .topmenu li a:hover {
    color:#00CCFF;
    text-decoration:none;
    list-style-type:none;
    }
我希望这对你有帮助。