timbmg
timbmg

Reputation: 3328

Add class based on site

I am inlcuding my navigation with php: <?php include('navigation.php');?>. Based on which site the user is the style of the navigation shall change. Therefore I need to add a class to the <li> element of my navigation.

I thought on making a switch statement on the $(document).ready function. But how can I get the called site to add the class at the correct <li>? Or is there a better best practice for my problem?

navigation.php

<div id="menu">
        <div class="pure-menu pure-menu-open">

        <ul>
            <li id="lielem1"><a href="#">Elem1</a></li>
            <li id="lielem2"><a href="#">Elem2</a></li>             
            <li id="lielem3" class="menu-item-divided pure-menu-selected">
                <a href="#">Elem3</a>
            </li>
        </ul>
    </div>
</div>

Upvotes: 1

Views: 59

Answers (1)

Mateusz Majewski
Mateusz Majewski

Reputation: 280

To apply "class-for-login" class on /login page you do:

<li id="lielem1" class="<?php echo $_SERVER[REQUEST_URI] == "/login" ? "class-for-login-page" : ""; ?>">Elem1</li>

Upvotes: 2

Related Questions