admin管理员组

文章数量:1312805

OK , I have a Custom Theme generated by Bootstrap. Currently I just added a Navbar (navigation to the theme and I am having trouble on setting ACTIVE navbar in each active page.(by adding active class to the li) For example if I am in Contact us page how I can force the navbar to make the contact us nav active! I alreadt tried

<li <?php is_page( 'Home' ){echo 'class="active"'}> Home</li>
<li <?php is_page( 'About us' ){echo 'class="active"'}> About us</li>

can you please let me know how I can do this?

OK , I have a Custom Theme generated by Bootstrap. Currently I just added a Navbar (navigation to the theme and I am having trouble on setting ACTIVE navbar in each active page.(by adding active class to the li) For example if I am in Contact us page how I can force the navbar to make the contact us nav active! I alreadt tried

<li <?php is_page( 'Home' ){echo 'class="active"'}> Home</li>
<li <?php is_page( 'About us' ){echo 'class="active"'}> About us</li>

can you please let me know how I can do this?

Share Improve this question edited Nov 18, 2013 at 14:15 Mona Coder asked Nov 18, 2013 at 12:09 Mona CoderMona Coder 4062 gold badges6 silver badges20 bronze badges 1
  • Please edit your question to make clear and understandable what you're asking, additionally read How to Ask. – Nicolai Grossherr Commented Nov 18, 2013 at 12:29
Add a comment  | 

1 Answer 1

Reset to default 1

Looks like its just your PHP formatting, you have the right idea! try this:

<pre class="prettyprint"><code class="language-php">
<?php 

if (is_page( 'Home' ) {
    $class="active";
}
elseif (is_page( 'About' ) {
    $class="active";
}
else {
    $class="";
}

?>

<li class="<?php echo $class; ?>"Home</li>
<li class="<?php echo $class; ?>"About</li>
</code></pre>

本文标签: theme developmentSeeting Active Nav for Bootstrap in WordPress