首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >3级Wordpress导航问题

问3级Wordpress导航问题
EN

Stack Overflow用户
提问于 2013-05-10 08:36:14
回答 1查看 196关注 0票数 0

我还在摆弄这个愚蠢的导航菜单。其思想是,当您第一次转到页面时,列出顶级页面,当单击其中一个页面时,二级菜单显示在其下方,其中包含所有选定的页子页面,而当单击其中一个页面时,选定二级页面中的所有第三级页面都显示在二级页面的下方。

我尝试过各种方法,我甚至尝试创建一个会话存储来记住某些部分,但我就是找不出一个好的解决方案。

以下是我到目前为止所做的工作:

代码语言:javascript
复制
<?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

EN

回答 1

Stack Overflow用户

发布于 2013-05-10 17:51:24

这是我对submenu....etc的子菜单和子菜单的解决方案。

我这样调用菜单:

代码语言:javascript
复制
 <?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,你可以根据自己的意愿进行定制。

代码语言:javascript
复制
.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;
    }

我希望这能对你有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16473389

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档