Sohail Saif
Sohail Saif

Reputation: 5

How to make a href class=active on my php code

I have following php code for horizontal menu, where I am calling the respective page from this php file, but I want whenever I call that page, that a href page become active.

<li class="mt">
    <li class="sub-menu">
        <a class="active" href="main.php">
            <i class="fa fa-dashboard"></i>
            <span>Dashboard</span>
        </a>
        <ul class="sub">
            <li><a href='?url=profile/profile.php'><span>My Profile</span></a></li>
            <li><a href='?url=profile/editprofile.php'><span>Edit my profile</span></a></li>
            <li><a href='?url=profile/welcome-letter.php'><span>Welcome Letter</span></a></li>
            <li class='last'><a href='?url=profile/change-password.php'><span>Change Password</span></a>
            </li>
        </ul>
    </li>
    </li>


    <?php if ($epin_module == TRUE) { ?>
        <li class="sub-menu">
            <a href="javascript:;">
                <i class="fa fa-cogs"></i>
                <span>My e-PIN</span>
            </a>
            <ul class="sub">
                <li ><a href='?url=epin/used.php'><span>Used e-Pin</span></a></li>
                <li><a href='?url=epin/un-used.php'><span>Unused e-Pin</span></a></li>
                <li><a href='?url=epin/request.php'><span>Request e-Pin</span></a></li>
                <li><a href='?url=epin/transferreport.php'><span>E-PIN Transfer report</span></a></li>
                <?php if ($autowithdraw == FALSE) { ?>
                    <li class='last'><a href='?url=epin/epingenerate.php'><span>E-PIN generate report</span></a>
                    </li>
                <?php } ?>
            </ul>
        </li>

I want when the MY e-Pin page is visited, that page became active. currently if I visit that page main.php stays active always.

Upvotes: 0

Views: 294

Answers (1)

GGO
GGO

Reputation: 2748

You can test url GET parameter for each links like that :

<a href="?url={MyUrl}" class="<?php if($_GET["url"] == "{MyUrl}"){ echo "active"; } ?>"></a>

Where you have to replace both {MyUrl} by the real url value.

Upvotes: 1

Related Questions