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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:35:51+00:00 2026-06-14T14:35:51+00:00

I have an index.php page which includes a navBar.inc page to render the top

  • 0

I have an index.php page which includes a navBar.inc page to render the top nav bar. I also have an external stylesheet. My goal is to highlight the current page in that navbar via PHP.

I’ve tried to implement it, but it isn’t working as I expected.

I placed PHP code at the top of the index.php page: <?php $thisPage="About"; ?>

Then in each li in the navBar.inc file, I have code that is supposed to change the id of each li, for example: <li><?php if ($thisPage=="About") echo " id=\"currentPage\""; ?>><a href="index.php">ABOUT</a></li>

And of course, in my external CSS I have: #currentPage {color:black;}

But when I upload the files to the server and try it out, it actually writes id=”currentPage” to the page rather than assigning it that id. Also, there are >’s between each menu item. See image link below.

Image

Can you help me get this working? I’m almost there I think! Thanks!

Note: This is my very first exposure to PHP. Syntax is a bit confusing, but looks interesting!

  • 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-14T14:35:52+00:00Added an answer on June 14, 2026 at 2:35 pm

    You are currently closing the <li> tag prior to echoing the variable, which means it’s rendering the id attribute and the > to screen:

    <li><?php if ($thisPage=="About") echo " id=\"currentPage\""; ?>>
       ^                                                            ^
    <a href="index.php">ABOUT</a></li>
    

    You need to place your id attribute inside the <li> element like this:

    <li<?php if ($thisPage=="About") echo " id=\"currentPage\""; ?>>
    <a href="index.php">ABOUT</a></li>
    

    As mentioned, you could accomplish this using javascript/jQuery, but this will work.

    EDIT:

    Try:

    #currentPage a { color: black !important; }
    

    Which overrides the prior styles you’ve set in your .CSS file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page called index.php which is calling a function writelog in includes/Logger.php
I have a page called index.php which includes a page new_display.php which again includes
I have folders and pages /admin/add/index.php, /admin/edit/index.php & /admin/view/index.php which all are requiring page
I have index.php page which makes a ajax call to thread.php by sending the
How it should work: Index.php is the secured page. It includes check.php, which checks
I have an index.php, which at it's very start includes db.php - file which
So I have a regular PHP page which includes the header, body, and the
I have a index.php page that is the main page. All pages are included
I have my index.php page and just afrer my header i want to include
i have a question, i have a index.php page that is the intro of

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.