duanlong4890
duanlong4890
2013-04-24 09:55

在一个页面wordpress上显示辅助导航

I have this bit of code in my header:

        <?php if (has_nav_menu('sub-header-menu', 'responsive')) { ?>
            <?php wp_nav_menu(array(
                'container'       => '',
                'menu_class'      => 'sub-header-menu',
                'theme_location'  => 'sub-header-menu')
                ); 
            ?>
        <?php } ?>

And I need something that will make it only show on the blog page and the children for that page (i.e the categories).. I'm not great with PHP but I guess this would be something simple

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • douyu8187 douyu8187 8年前

    Just add a page Id of your blog page in you condition.

    $parentPageId = is_subpage();
    if (has_nav_menu('sub-header-menu', 'responsive') &&
       (is_page( $blogPageId ) || $parentPageId == $blogPageId))
    

    You can alos check your page using slug.

    is_page( 'blog' ) 
    

    Function to get Parent Page Id if exists.

    function is_subpage() {
        global $post;
        if ( is_page() && $post->post_parent ) {
            return $post->post_parent;
        } else {
            return false;
        }
    }
    
    点赞 评论 复制链接分享
  • duancong2160 duancong2160 8年前

    Find out the ID of the blog page $blogid = 123 (for example) and then check with if ($page->ID == $blogid) { /*show menu*/ }

    点赞 评论 复制链接分享

为你推荐