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 343845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:56:08+00:00 2026-05-12T10:56:08+00:00

My PHP site has header,body,footer files that are included into the INDEX.PHP page. On

  • 0

My PHP site has header,body,footer files that are included into the INDEX.PHP page.
On the header.php file I have a menu like this

    <div id="bottomrow"> 
      <div class="pad"> 
        <ul class="menu left">
          <li class="first <?=$current_home?>"><a href="/"><em>Home</em></a></li>
          <li class="users drop <?=$current_users?>"><a href=""><em>Users</em></a><span class="drop">&nbsp;</span> 
            <ul id="moreheader">
                <li></li>
                <li></li>

            </ul>
          </li>
          <li class="<?=$current_forum?>"><a href=""><em>Forums</em></a></li>
          <li class="drop <?=$current_more?>"><a href="/moreheader"><em>More</em></a><span class="drop">&nbsp;</span> 
            <ul id="moreheader">
              <li><a href=""><em>Widgets</em></a></li>
              <li><a href=""><em>News</em></a></li>
              <li><a href=""><em>Promote</em></a></li>
              <li><a href=""><em>Development</em></a></li>
              <li><a href=""><em>Bookmarks</em></a></li>
              <li><a href=""><em>About</em></a></li>
            </ul>
          </li>
          <li class="moneytabmenu <?=$current_money?>"><a href="/moneytabmenu"><em>Money:<span class="moneytabmenu-total">$0.00</span></em></a></li>
        </ul>
        <ul class="menu right">
          <li class="drop myaccount <?=$current_myaccount?>"><a href="" class="first"><img class="avatar" src="http://gravatar.com/avatar.php?gravatar_id=7ab1baf18a91ab4055923c5fd01d68a2&amp;rating=pg&amp;size=80&amp;default=" height="19" width="19" alt="you" /><em>My 
            Account</em></a><span class="drop">&nbsp;</span> 
            <ul id="myaccount">
              <li><a href=""><em>Dashboard</em></a></li>
              <li><a href=""><em>Account Settings</em></a></li>
              <li><a href=""><em>Settings</em></a></li>
            </ul>
          </li>
          <li class="drop"><a href=""><em>Mail</em></a><span class="drop">&nbsp;</span> 
            <ul id="mailboxheader">
              <li><a href=""><em>InBox</em></a></li>
              <li><a href=""><em>SentBox</em></a></li>
              <li><a href=""><em>Trash</em></a></li>
              <li><a href=""><em>Post Bulletin</em></a></li>
              <li><a href=""><em>View Bulletins</em></a></li>
            </ul>
          </li>
          <li class="drop <?=$current_more?>"><a href=""><em>More</em></a><span class="drop">&nbsp;</span> 
            <ul id="moreheader">
              <li><a href=""><em>Widgets</em></a></li>
              <li><a href=""><em>News</em></a></li>
              <li><a href=""><em>Promote</em></a></li>
              <li><a href=""><em>Development</em></a></li>
              <li><a href=""><em>Bookmarks</em></a></li>
              <li><a href=""><em>About</em></a></li>
            </ul>
          </li>
        </ul>
      </div>
    </div>
    <!-- END div#bottomrow -->
  </div> 

The menu is similar to above, the above menu is not completed but you can see how it is set up, there are

  • list items that make up a menu and SOME of the list items have SUB-LIST items to make up sub-menus on some of the main menu items.

    If a user is on any of the pages in a sub-menu, it should add the “current” css class to the parent menu item.

    Below is my index.php page where I can determine which page I am on using $_GET for the variable index.php?p=PAGE-NAME

    I posted a question earliar similar to this but it was before I did the code below and it didnt get much response, the response it did get all mentioned using arrays but that was beofre they new that I had sub-menus.

    So does anyone see a better way to add the css class “current” to a list item above based on which page I am on?


    Code on INDEX.php page that processes which menu item should be highlighted

    //set variables for menu item to appear as being SELECTED 
    $p = $_GET['p'];
    
    $current_home = '';
    $current_users = '';
    $current_forum = '';
    $current_more = '';
    $current_money = '';
    $current_myaccount = '';
    $current_mail = '';
    //if home then highlight home menu
    if($p === 'home'){
        $current_home = 'current';
    }
    if($p === 'users.online' || $p === 'users.location' || $p === 'users.featured' || $p === 'users.new' || $p === 'users.browse' || $p === 'users.search' $p === 'users.staff'){
        $current_users = 'current';
    }
    if($p === 'forum'){
        $current_forum = 'current';
    }
    if($p === 'widgets' || $p === 'news' || $p === 'promote' || $p === 'development' || $p === 'bookmarks'  || $p === 'about'){
        $current_more = 'current';
    }
    if($p === '=account.money' || $p === 'account.store' || $p === 'account.lottery' || $p === 'users.top.money'){
        $current_money = 'current';
    }
    if($p === 'account'){
        $current_myaccount = 'current';
    }
    if($p === 'mail.inbox' || $p === '=mail.sentbox' || $p === 'mail.trash' || $p === 'bulletins.post' || $p === 'bulletins.my'  || $p === 'bulletins'){
        $current_mail = 'current';
    }
    
    • 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-05-12T10:56:08+00:00Added an answer on May 12, 2026 at 10:56 am

      I would recommend making the whole thing more data driven. Create a multi-dimensional array of your menu options and then iterate through the array, outputting the correct HTML.

      Here’s how I would do it (this hasn’t been tested, but the idea is what I’m trying to convey):

      <?
          $p = $_GET['p'];
      
          $navArray = array();
          $navArray['home'] = array('main' => array('id'=>'home', 'url'=>'/', 'title'=>'Home'));
          $navArray['more'] = array('main' => array('id'=>'more', 'url'=>null, 'title'=>'More'), 
                                    'pages'=> array(
                                      array('id'=>'widgets', 'url'=>'/more-widgets.php', 'title'=>'Widgets'),
                                      array('id'=>'news', 'url'=>'/news.php', 'title'=>'News')));
      
      ?>
      
      
      <div id="bottomrow"> 
            <div class="pad"> 
              <ul class="menu left">
      
                  <? foreach($navArray as $navHeading) : ?>
                      <? $current = $navHeading['main']['id'] == $p ? 'current' : ''; ?>
                      <li class="first <?=$current?>"><a href="<?=$navHeading['main']['url']?>"><em><?=$navHeading['main']['title']?></em></a></li>
      
                      <? if (!empty($navHeading['pages'])) : ?>
                          <ul id="sub-<?=$navHeading['main']['id']?>">
                          <? foreach($navHeading['pages'] as $navPage) : ?>
                              <? $current = $navPage['id'] == $p ? 'current' : ''; ?>
                              <li class="<?=$current?>"><a href="<?=$navPage['url'];?>"><em><?=$navPage['title']?></em></a></li>
                          <? endforeach; ?>
                          </ul>
                      <? endif; ?>
                  <? endforeach; ?>
              </ul>
          </div>
      </div>
      
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

    Sidebar

    Related Questions

    Information: I have a site that has a design on index.php, and then you
    I have a file that is called header (the header of my site).. I
    index.php has this jquery code which loads notifications.inc.php into a div on the page
    I have a site that uses the odd header() PHP command after a form
    I've been working on an internal site that has Apache / PHP running. I
    I'm working on a database site now that has the URL structure: example.com/f.php?id=12 I'd
    I have a PHP site that uses a fairly common authentication scheme. The entire
    I have a global.php file that I call from the top of every script.
    Greetings, I have a php site that was working fine as of the start
    I have a php site where a user has the ability to login. Once

    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.