【问题标题】:menu highlight current post菜单突出显示当前帖子
【发布时间】:2012-06-25 17:42:30
【问题描述】:

我正在使用带有非常基本主题的 wordpress 默认安装。我遇到的问题是,当我查看帖子、普通帖子或自定义帖子类型时,菜单不会突出显示。

例如,我点击“博客”,博客文章存档页面显示并且菜单仍然正确突出显示,但是当我打开随机帖子时,菜单突出显示消失了。

有什么解决办法吗?

【问题讨论】:

    标签: wordpress menu highlight


    【解决方案1】:

    巧合的是,我昨天为这个客户的主题设置了一些东西。你可能有一个突出菜单项的类?你能发布你的主题代码是什么样子的——可能这在主题中的 header.php 之类的东西中。

    我所做的是将页面标题与菜单项进行比较,然后设置该类。比如:

    class="<?php if(trim(wp_title("",false))=="Home") echo "active"; ?>"
    

    如果 wp_title 为“Home”,则将类设置为“活动”。这是一个静态导航菜单,每个页面都有链接;您的可能在循环打印页面标题以进行导航时是动态的,因此很高兴看到您的代码能够提供帮助。

    【讨论】:

      【解决方案2】:

      或者你可以有条件,

      <?php if (is_single() ?>
      

      【讨论】:

        【解决方案3】:
        For highlighting a particular menu,you can try this in ur style.css file of your website:-
        
        #nav li.current_page_item a{
        color:#fff !important;
        background-color:#82bd42;
        text-decoration:none;
        -moz-border-radius: 3px;
        -webkit-border-radius: 3px;
         border-radius: 3px;
        padding:10px 10px;
        }
        
        Where nav is the id of the <nav id="id"> tag where menu is being located in 
        header.php,like this:-
        
        <nav id="nav">
        
          <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
        
        </nav>
        

        【讨论】:

          猜你喜欢
          • 2021-04-07
          • 2019-02-16
          • 1970-01-01
          • 1970-01-01
          • 2013-11-18
          • 2019-07-28
          • 2012-09-17
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多