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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:31:16+00:00 2026-05-15T22:31:16+00:00

The problem: I want to use PHP include to import file header_menu.html into all

  • 0

The problem:
I want to use PHP include to import file “header_menu.html” into all pages that share the same navigation menus, but each page has its own current highlighted menu item.

For example, the following are the menus, in index.php, only the first should be set to “current” class, and in download.php, only the second should be current. How to do that with JavaScript? Can you provide a detailed working sample? You know, I don’t want to duplicate the menus in each page…

<li><a href="../index.php" class="current">Home</a></li>
<li><a href="../download.php">Download</a></li>
<li><a href="../purchase.php">Buy</a></li>

Thank you!


Edit: PHP solutions are also welcomed!

  • 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-15T22:31:17+00:00Added an answer on May 15, 2026 at 10:31 pm

    The best solution is with php. There is a function that tells what page is calling it. You put that in the include and use an if statement to decide which menu item to set to class="current"

    Here is the function I found on the internet that helped me do it

    <?php
    $a = basename($_SERVER['REQUEST_URI'], ".php"); /* supposing filetype .php*/
    ?>
    

    Then the code in the header would look like

    <li <?php if($a=='index' || $a==''){echo("class='current'");}?>><a href='index.php'>Home</a></li>
    <li <?php if($a=='download'){echo("class='current'");}?>><a href='download.php'>Download</a></li>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use MSVC compiler to build a DLL file. The problem is
The problem I'm having is that I want to use STL's sort with a
I have a problem, I have a saved text file, I want to use
I use those js files below: jquery-1.4.2.min.js include/jcarousel/lib/jquery.jcarousel.min.js include/mousewheel/jquery.mousewheel.js in my index.php file i
I want to share the content of my HTML head tag among several pages
I use php files in my website and in those file I include my
Problem I want to use the interactive debugger with IntelliJ. Unfortunately, I can't convince
I'm working on machine learning problem and want to use linear regression as learning
I want to use cglib as my proxy mechanism for spring. problem is, i
this is a post back problem (I don't want to use the client side

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.