0

I have a navbar which is accessible by all the pages through header.php But I need different navbar for home page and different one for the rest of the pages.

I have made this navbar absolute and transparent for the home page by addidng css like this :

`

.navbar-inverse-blue .navbar-inner {
    padding: 7px 0;
    background: rgba(51, 51, 51, 0.3);
    border: none;
    font-size: 0.85em;
    position: absolute;
    z-index: 9999;
    width: 100%;
}

`

But in other page i want to change that navbar fixed and non-transparent and for that i have the css also

.navbar-inverse-blue .navbar-inner {
padding: 7px 0;
border: none;
font-size: 0.85em;
z-index: 9999;
width: 100%;

}

and this is my HTML CODE`

<div  id="nav-wrapper" data-spy="affix" data-offset-top="200"  class="navbar navbar-inverse-blue navbar">
<!--<div class="navbar navbar-inverse-blue navbar-fixed-top">-->
  <div class="navbar-inner">
    <div class="container">
       <div class="navigation">
         <nav id="colorNav">
           <ul>
            <li class="green">
                <a href="#" class="icon-home"></a>
                <ul>
                    <li><a href="login.html">Login</a></li>
                    <li><a href="register.html">Register</a></li>
                    <li><a href="index.html">Logout</a></li>
                </ul>
            </li>
           </ul>
         </nav>
       </div>
       <a class="brand" href="<?php echo esc_url(home_url('/')); ?>"><img src="<?php header_image(); ?>" alt="logo"></a>
       <div class="pull-right">
        <nav class="navbar nav_bottom" role="navigation">
        <!-- Brand and toggle get grouped for better mobile display -->
      <div class="navbar-header nav_2">
          <button type="button" class="navbar-toggle collapsed navbar-toggle1" data-toggle="collapse" data-target="#bs-megadropdown-tabs">Menu
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#"></a>
       </div> 
       <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-megadropdown-tabs">


            <?php
        wp_nav_menu( array(
            'menu'              => 'primary',
            'theme_location'    => 'primary',
            'depth'             => 2,
            'container'         => 'div',
            'container_class'   => 'collapse navbar-collapse',
            'container_id'      => 'bs-example-navbar-collapse-1',
            'menu_class'        => 'nav navbar-nav nav_1',
            'fallback_cb'       => 'WP_Bootstrap_Navwalker::fallback',
            'walker'            => new WP_Bootstrap_Navwalker())
        );
    ?>
         </div><!-- /.navbar-collapse -->
        </nav>
       </div> <!-- end pull-right -->
      <div class="clearfix"> </div>
    </div> <!-- end container -->
  </div> <!-- end navbar-inner -->
</div>

But I dont' know where to put that code. As i am calling header.php in every page.

Dipankar Das
  • 131
  • 2
  • 11
  • Give the `html` or `body` element a class depending on the page you are on; then use that in your CSS selectors. – CBroe May 03 '17 at 09:14
  • are you open to use jquery? – Sahil Dhir May 03 '17 at 09:21
  • This should not really be a CSS question in the first place. Instead, inside your header template, you should check what page you are on (WordPress has functions such as is_home etc. for that), and then output the appropriate menu, and only that. – CBroe May 03 '17 at 09:22
  • Use this answer to add class to your body... then write css according to parent..http://stackoverflow.com/questions/33282929/add-class-to-body-on-homepage – Sahil Dhir May 03 '17 at 09:23

1 Answers1

0

Another approach is to add/remove the menu items using a filter:

add_filter("wp_nav_menu_items", "new_menu_items");

You could completely remove all menu items and add new ones depending on the page you are on. Small example of one of my projects:

function new_menu_items($items) {
   if(!is_user_logged_in) {
      $items .=  "<li class='menu-item'><a href='" . get_site_url() . "/login/' data-level='1'><span class='menu-item-text'><span class='menu-text'>" . __("Inloggen", "sz") . "</span></span></a></li>";
   }
}
berend
  • 553
  • 2
  • 12