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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:13:34+00:00 2026-05-27T10:13:34+00:00

So I have searched SO for an hour trying to find the answer, and

  • 0

So I have searched SO for an hour trying to find the answer, and also tried various methods, including this

I am trying to include my pages, along with the navigation. But on the correct page, I need the list-item to have a class of active. The navigation is in header.php and currently looks like this:

<nav>
    <ul>
      <li class="active"> <a href="/">Home</a> </li>
      <li> <a href="#">Apps</a> </li>
      <li> <a href="#">Forums</a> </li>
    </ul>
  </nav>

First, I have no idea if JS(jQuery) would be better, or if PHP was to be better. Both wouldn’t matter if it works.

Also I am a bit new with PHP and trying to learn.

What would be the easiest (hopefully) method to use? So I don’t have to change a lot of code just to give a nav class="active"

  • 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-27T10:13:35+00:00Added an answer on May 27, 2026 at 10:13 am

    Asumming you have a $page variable (which contains the name of the page you are currently on):

      <nav>
        <ul>
          <li class="<?php echo ($page == "home" ? "active" : "")?>"> <a href="/">Home</a> </li>
          <li class="<?php echo ($page == "apps" ? "active" : "")?>"> <a href="#">Apps</a> </li>
          <li class="<?php echo ($page == "forums" ? "active" : "")?>"> <a href="#">Forums</a> </li>
        </ul>
      </nav>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched Google for the past hour and can't find the answer to
I've searched for about an hour on this and couldn't find an answer so
I have searched for a general solution to this but only find answers to
I have searched this site for an answer and found many responses to unsigned/signed
I am a new programmer and have searched for this answer, but think I
I have searched and can not find the answer. I double checked the data
I have searched this site extensively but cannot find a solution. Here is the
I have searched the web but could not find an answer. how do I
I've searched for the last half an hour trying to find a way to
I have been at this for well over an hour and searched here and

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.