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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:58:00+00:00 2026-05-16T08:58:00+00:00

I am looking for the best way to set a list item’s currentmenu class,

  • 0

I am looking for the best way to set a list item’s currentmenu class, in order to show the user the current active menu selected using php.

I have moved my html/css site over to WordPress but originally had all my code inside my index.html file that consisted of a sidemenu div and jQuery processing to toggle between active menu selections.

The code I originally has in my index.html is:

HTML Code for Sidebar Menu using Superfish:

    <div id="sidebar">
        <ul id="themenu" class="sf-menu sf-vertical">
            <li><a href="index.php" class="topm currentMenu nosub">Home</a></li>
            <li><a href="about-us.php" class="topm nosub">About Us</a></li>
       </ul>
</div>

jQuery Code for Toggling Current Active Menu:

$("ul.sf-menu li a").click(function() {
    $("ul.sf-menu li a").not(this).removeClass("currentMenu");
    $(this).toggleClass("currentMenu");
});

As this was all in the one index.html file, all worked fine.

Now with the move to WordPress and so moving my sidebar menu div into its own sidebar.php file and in addition to this, having created individual custom wp page for about-us.php which calls in the sidebar.php file, I have the following issue occurring, which is where I want to determine the best means to solve my issue.

The issue is, when the user first comes into the site, the index.php file fires and based on the above, the “Home” menu is currently the active menu based on default class value. But when the user presses the “About Us” menu option, which then calls my about-us.php page I created, that also calls the sidebar.php file, the current active menu is still the “Home” menu option, which is not correct.

Ho can I make the “About Us” menu option now the active menu, i.e. have the class “CurrentMenu” now set for About Us” as I am not sure how to approach this in php as my jQuery toggling code no longer works?

I am proposing to have additional menu options with their own wordpress page templates calling the sidebar.php file and so will need to have those menu option set as class=”currentMenu”.

  • 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-16T08:58:00+00:00Added an answer on May 16, 2026 at 8:58 am

    Sounds like you are looking for wordpress conditional tags. For example:

    <div id="sidebar">
        <ul id="themenu" class="sf-menu sf-vertical">
            <li><a href="index.php" class="topm <?php if (is_home()) { echo "currentMenu"; } ?> nosub">Home</a></li>
            <li><a href="about-us.php" class="topm <?php if (is_page('about-us')) { echo "currentMenu"; } ?> nosub">About Us</a></li>
       </ul>
    </div>
    

    The first nav line checks to see if the current page is the homepage, if so it prints the required tag for the menu. The second line checks to see if the page is the “about-us” page, where “about-us” is the post_name (slug). You could also use the post ID. For more examples/references of available relevant tags, check my link below. Hope this helps.

    Reference: http://codex.wordpress.org/Conditional_Tags
    Reference: http://codex.wordpress.org/Dynamic_Menu_Highlighting

    To do this in standard PHP, avoiding using wordpress as platform, you could do something like this, or just assign a variable of the specific pages directly:

    <?php
    $path = $_SERVER['PHP_SELF'];    // get the path to the file
    $page = basename($path);         // grab the filename
    $page = basename($path, '.php'); // remove the .php extension
    ?>
    
    <div id="sidebar">
        <ul id="themenu" class="sf-menu sf-vertical">
            <li><a href="index.php" class="topm <?php if ($page == "index") { echo "currentMenu"; } ?> nosub">Home</a></li>
            <li><a href="about-us.php" class="topm <?php if ($page == "about-us") { echo "currentMenu"; } ?> nosub">About Us</a></li>
       </ul>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking for the best way to set-up an iPhone project in XCode ... namely:
I am looking for the best or any way to set the Album Art
I'm looking for a best way to represent a set of structural data. I'm
I'm looking for best way of using session within zf application. At first I
I am looking for the best way to do a One Time Login for
I'm looking for the best way to get quantity of my unique visitors on
I'm looking for the best way to escape some Javascript text in PHP, and
I'm looking for the best way to select numbers directly from an in clause.
I'm looking for the best way of loading formatted data in VBA. I’ve spent
I'm looking for the best way to use a duration field in a Rails

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.