douyi4991 2014-11-12 14:51
浏览 29

在子页面上删除导航突出显示(wordpress)

When you click on the navigation on this webpage, the nav element stays highlighted. If you navigate to one of the inner pages, the highlight goes away. How can we keep the highlight on subpages of that page?

http://www.allinsure.ca/services/ - Try clicking to a subpage; the grey highlight on Services is no longer there. Applies to all pages with subpages.

Any thoughts on how to fix this? I also notice that the breadcrumbs don't direct back to the previous page - instead it links to Portfolio Categories.

Perhaps there's a way to say "When this page is selected, highlight this navigation item."

We're using Cherry Framework. That and wordpress are both up-to-date.

Thanks all!

  • 写回答

1条回答 默认 最新

  • duanchun2349 2014-11-12 15:31
    关注

    Have a look at the class "current-page-ancestor" which is set by wordpress to your main navigation when you are on a subpage.

    So you can solve this with pure css.

    simply change this part in your main-style.css from:

    .header .nav__primary .sf-menu li.current-menu-item a, 
    .header .nav__primary .sf-menu .sfHover a,     
    .header .nav__primary .sf-menu .current-menu-parent a{
       background: none repeat-x scroll 0 0 #58585a;
       box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
       color: #fff;
    }
    

    to:

    .header .nav__primary .sf-menu li.current-menu-item a, 
    .header .nav__primary .sf-menu .sfHover a,     
    .header .nav__primary .sf-menu .current-menu-parent a,
    .header .nav__primary .sf-menu li.current-page-ancestor a{
       background: none repeat-x scroll 0 0 #58585a;
       box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
       color: #fff;
    }
    

    I've just noticed that the "current-page-ancestor" class works only for page types but not for custom types. To hightlight the Services page when you are on a protfolio entry, it is a bit more complicated. You could achieve it by using the filter nav_menu_css_class.

    function _nav_menu_css_class($classes)
    {
        switch (get_post_type()){
        case 'portfolio':
    
            $idOfServicePage = 1;
    
            if (in_array('menu-item-'.$idOfServicePage, $classes)){
                $classes[] = 'current-menu-item'; // or current-page-ancestor
            }
    
            break;
    
        }
        return $classes;
    }
    add_filter('nav_menu_css_class', '_nav_menu_css_class');
    

    Sorry I can not check my code right now, but I have had a similar issue and could solve it by using the nav_menu_css_class filter.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)