在子页面wordpress上的活动父链接和子链接

时间:2016-07-25 10:18:29

标签: css wordpress menu

我正在构建这个网页,其中有子页面的页面,当我点击导航菜单中的父链接时,我被重定向到该页面。然后它将显示该页面上所有子页面的链接,我的问题是我希望导航菜单中的父页面链接始终突出显示,即使我单击子页面链接。因此,最后应突出显示父页面链接和子页面链接。

我尝试了一些不同的东西,但似乎都没有用,我可以循环显示父级的所有子页面,但不会突出显示它们。

    <?php

     if ( $post->post_parent ) :
       $parent = $post->post_parent;
     else :
       $parent = $post->ID;
     endif;

     $childpages = get_pages('child_of=' . $parent .        '&sort_column=menu_order');

     ?>

    <div class="row pad60">
     <ul class="category-nav column">
       <?php foreach( $childpages as $childpage ) { ?>

            <a href="<?= get_page_link( $childpage->ID ) ?>">
                <li><div class="primary-btn"> <?= $childpage->post_title ?> </div></li>
            </a>

     <?php } // End foreach ?>
   </ul>
</div>

这就是我现在正在使用的,但我觉得这不是一开始的正确方法..

谢谢!

1 个答案:

答案 0 :(得分:0)

WordPress有一个CSS类的内置来定位菜单。 https://developer.wordpress.org/reference/functions/wp_nav_menu/#Menu_Item_CSS_Classes

// This will highlight all the current menus
.current-menu-item a {
    color: blue;
    }

/* This will highlight its parent, when you are in its child page. */
.current_page_parent a {
    color: orange;
    }
相关问题