0

I want to use a file called header.php which includes a bootstrap navbar header, is it possible to change for example the 'active' tab in the menu dynamically according to the specific page I am on?

Header.php file:

<div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <a href="#" class="navbar-brand">Example Website</a>
        </div>

        <ul class="nav navbar-nav">
            <li class="active" id="page1">Page 1</li>
            <li id="page2">Page 2</li>
            <li id="page3">Page 3</li>
        </ul>
    </div>
</div>

Let's say I include this with php into page1.php, page2.php and page3.php, How can I dynamically change the active tab from header.php to for example Page 2 in case of being on page 2?

Update: I found a solution. Thanks to one of the 'duplicate' references.

Azoraqua
  • 155
  • 1
  • 12
  • *Yes,* it is possible. I could easily give you links from a Google search of "if current active page php" but feel you should be doing that. You may not have known what to look for, now you do ;-) – Funk Forty Niner Jun 02 '16 at 15:08
  • Please post a working example of your code (HTML/CSS/JS) in a [Snippet](https://blog.stackoverflow.com/2014/09/introducing-runnable-javascript-css-and-html-code-snippets/). See [mcve] and [ask]. – vanburen Jun 02 '16 at 15:10
  • I've added some code, to make it a bit more explaining, itself. – Azoraqua Jun 02 '16 at 18:36
  • I can think of at least one way to do this in pure JS, one with a JS framework, and 3 or more in PHP. What have *you* thought about? Do you have an idea ... have you flow-charted the logic process? – Kevin_Kinsey Jun 02 '16 at 18:37
  • I prefer to use PHP as much as it's possible to use. But otherwise I wouldn't mind to use jQuery instead. – Azoraqua Jun 02 '16 at 18:38
  • 2
    Possible duplicate of [Make Twitter Bootstrap navbar link active](http://stackoverflow.com/questions/11813498/make-twitter-bootstrap-navbar-link-active) – vanburen Jun 02 '16 at 20:48
  • @vanburen Thank you this actually helped me out. – Azoraqua Jun 02 '16 at 21:52

0 Answers0