Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7984705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:21:29+00:00 2026-06-04T11:21:29+00:00

I use these files as base for my website: The menu.php : $p =

  • 0

I use these files as base for my website:

The menu.php:

$p = $_GET['p'];

switch($p)
{
    case "home":
        $p = "page/home.php";
    break;

    case "customers":
        $p = "page/customers.php";
    break;

    default:
        $p = "page/home.php";
    break;
}

<ul id='nav'>

   <li>Title</li>
    <ul>
        <li class="nav active"><a href="?p=home">Home</a></li>
        <li><a href="?p=customers">Customers</a></li>
    </ul>
</ul>

The default.php:

<body>
 <div id='navcontainer'>
  <?php include ("menu.php"); ?>
 </div>

<div id='content'>
 <?php include ($p); ?>
</div>

The style.css:

#navcontainer {margin:0; padding:0; width:220px;float:left;}
#nav li {background:#36393D; color:#fff; padding:5px 3px 5px 20px; margin:4px;border-left:5px solid #3F4C6B;}
#nav ul li{display:block; padding:3px; background:#fff; color:#000;border:none; padding:3px 0 3px 30px;}
#nav ul li:hover, #nav ul li.active {background:#eee; cursor:pointer; border-left:5px solid #4096EE;padding:3px 0 3px 25px;}
#nav ul li a {text-decoration:none; color:#000;}

The home.php and all pages:

<p>Hello world!</p>

I wonder if it is possible to get my menu.php to switch class to nav activeon the <li> items based on what page is currently visited.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:21:30+00:00Added an answer on June 4, 2026 at 11:21 am

    Using just php, you can create an extra variable

    <?php
      $p = $_GET['p'];
      $currentPageId = 0;
    
      switch($p)
      {
        case "home":
            $p = "page/home.php";
            $currentPageId = 1;    
        break;
    
        case "customers":
            $p = "page/customers.php";
            $currentPageId = 2;    
        break;
    
        default:
            $p = "page/home.php";
            $currentPageId = 1;    
        break;
      }
    ?>
    
    <ul id='nav'>
    
       <li>Title</li>
        <ul>
            <li <?php if($currentPageId == 1) { echo 'class="nav active"'; } ?> ><a href="?p=home">Home</a></li>
            <li <?php if($currentPageId == 2) { echo 'class="nav active"'; } ?> ><a href="?p=customers">Customers</a></li>
        </ul>
    </ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My website is built using php files. I use trade secret algorithms in these
I use these two files here and here . I created a class in
I'm looking for a solution in PHP to programmatically set the CMS home page
I'm attempting to use a sample function on the PHP manual website (posted by
Is there a good and free SVN repository I could use to store files
Is there any library out there that I can use to create epub files
I use DOMDocument for editing some HTML files, but some of theme have in
I have to use mootools and jquery files together. But there is a conflict
I'm using PHP 5.2 to make a website I like to have explicit names
I have a wizard on my website in which several steps use the HTML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.