在 Wordpress 3.3.2 的菜单中隐藏/显示孙子页面


Hiding/showing grandchild pages in a menu in Wordpress 3.3.2

我有一个菜单问题,我想得到一些帮助。

我正在使用主题为二十一的wordpress 3.3.2。

我正在使用两个模板,默认的wordpress展示和一个名为产品的自定义页面模板。

我目前有这个子导航树(展示模板(:

  • -市场和产品
    • 农业
    • 航空 航天
    • 防御
    • 工业

我用来获得上述结果的代码是:

       <?php
        //$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=1&depth=1');
if($post->post_parent && $post->post_parent!=0){
        $children = wp_list_pages("title_li=&sort_column=menu_order&child_of=".$post->post_parent."&echo=0&depth=2");
}else{
          $children = wp_list_pages("title_li=&sort_column=menu_order&child_of=".$post->ID."&echo=0&depth=1");
     }
 if ($children) { ?>
    <div id="subNav">
        <ul>        
        <?php echo $children; ?>
        </ul>
    </div>
    <?php } ?>

当我选择农业页面(产品模板(时,我看到以下结构:

  • 营销与产品
    • 农业
      • 孙子第 1 页
      • 孙子第 2 页
    • 航空 航天
      • 孙子第 1 页
      • 孙子第 2 页
    • 防御
    • 工业
农业孙子页面

正在展示,但航空航天孙子页面应该隐藏。

我当前使用的代码是:

    <?php
       //$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=1&depth=1');
    // && $post->post_parent!=0
    if($post->post_parent){
    //siblings
    $textTest = 'siblings';
            $children = wp_list_pages("title_li=&sort_column=menu_order&child_of=".$post->post_parent."&echo=0&depth=2");
     }else{
            $textTest =  'children';
                    $children = wp_list_pages("title_li=&sort_column=menu_order&child_of=".$post->ID."&echo=0&depth=1");
          }
       if ($children) { ?>
        <div id="subNav">
            <? echo $textTest;?>
            <ul>        
               <?php echo $children; ?>
            </ul>
        </div>
    <?php } ?>

所以我想知道的是; 给定:市场营销页面的父级为 0它有孩子 航空航天和农业他们也有孩子(孙子到营销(

有没有办法显示:营销之子在该页面上农业的孩子(例如(在该页面上,或者在其子页面上之一 - 这样只有这些孙子和农业的兄弟姐妹(营销的孩子(,而不是它的兄弟姐妹的孩子?

任何帮助表示赞赏。 :)

您使用的其他 if 会导致冲突。

对每个页面使用meta value。 这决定了要在屏幕上显示的菜单类型。

还:

使用此代码,菜单将显示它将始终显示完整菜单。

就像您在Agriculture页面上一样,它将检查它是否有父页面,在这种情况下,Agriculture页面的父页面是Marketing & products页面,然后它选择父页面。

并且Marketing & products的所有子页面都显示在链接中。