Jump to content

Recommended Posts

I am using CSS to indicate which page you are on and PHP to use this menu as an include while still being able to determine the 'you_are_here" CSS.

 

work great on the home page

 

http://www.warriorsarise.org/index.php

 

you will see that the indicator is that you are on the home page

 

however, when you go here:

 

http://www.warriorsarise.org/About_Us/index.php

 

you will see that the menu indicates that you are still on the home page. This is what I am having an issue with.

 

I know why it is doing this. It is because my directory is set up as Contact_Us/index.php, Itinerary/index.php etc.

 

how do i alter my code, so that it picks up the right pages?

 

my PHP as it is now

 

<?php $currentPage = basename($_SERVER['SCRIPT_NAME']);?>
<ul id="top_menu">

       <li><a href="../index.php"<?php if ($currentPage == 'index.php'){echo 'id="active"';} ?>> Home</a></li>

       <li><a href="../About_Us/index.php"<?php if ($currentPage == '../About_Us/index.php') {echo 'id="active"';} ?>>About Us</a></li>

       <li><a href="../OnlineSermons/index.php"<?php if ($currentPage == '../OnlineSermons/index.php') {echo 'id="active"';} ?>>Online Sermons and Video</a></li>

       <li><a href="../Itinerary/index.php"<?php if ($currentPage == '../Itinerary/index.php') {echo 'id="active"';} ?>>Itinerary</a></li>

       <li ><a href="../Request_Visit/index.php"<?php if ($currentPage == '../Request_Visit/index.php') {echo 'id="active"';} ?>>Request a Visit to Your City</a></li>

              <li><a href="../Links/index.php"<?php if ($currentPage == '../Links/index.php') {echo 'id="active"';} ?>>Links</a></li>

       <li><a href="../Contact_Us/index.php"<?php if ($currentPage == '../Contact_Us/index.php') {echo 'id="active"';} ?>>Contact Us</a></li>

</ul>

 

Link to comment
https://forums.phpfreaks.com/topic/71750-css-and-menu-includes-issue/
Share on other sites

I tried this:

 

<?php $currentPage = basename($_SERVER['SCRIPT_NAME']);?>
<ul id="top_menu">

       <li><a href="../index.php"<?php if($_SERVER['REQUEST_URI'] == 'index.php'){echo 'id="active"';} ?>> Home</a></li>

       <li><a href="../About_Us/index.php"<?php if ($_SERVER['REQUEST_URI'] == 'About_Us/index.php') {echo 'id="active"';} ?>>About Us</a></li>

       <li><a href="../Online_Sermons/index.php"<?php if ($_SERVER['REQUEST_URI'] == '../Online_Sermons/index.php') {echo 'id="active"';} ?>>Online Sermons and Video</a></li>

       <li><a href="../Itinerary/index.php"<?php if ($_SERVER['REQUEST_URI'] == '../Itinerary/index.php') {echo 'id="active"';} ?>>Itinerary</a></li>

       <li ><a href="../Request_Visit/index.php"<?php if ($_SERVER['REQUEST_URI'] == '../Request_Visit/index.php') {echo 'id="active"';} ?>>Request a Visit to Your City</a></li>

              <li><a href="../Links/index.php"<?php if ($_SERVER['REQUEST_URI'] == '../Links/index.php') {echo 'id="active"';} ?>>Links</a></li>

       <li><a href="../Contact_Us/index.php"<?php if ($_SERVER['REQUEST_URI'] == '../Contact_Us/index.php') {echo 'id="active"';} ?>>Contact Us</a></li>

</ul>

 

but it doesn't give me the id="active" that I need to set the you are on this page css

 

See anything that might be wrong?

<?

$array=explode('/',$_SERVER['REQUEST_URI']);
$currentPage= $array[count($array)-2];
?>
<ul id="top_menu">

       <li><a href="../index.php"<?php if(count($array)<=1){echo 'id="active"';} ?>> Home</a></li>

       <li><a href="../About_Us/index.php"<?php if ($currentPage == 'About_Us') {echo 'id="active"';} ?>>About Us</a></li>

       <li><a href="../Online_Sermons/index.php"<?php if ($currentPage == 'Online_Sermons') {echo 'id="active"';} ?>>Online Sermons and Video</a></li>

       <li><a href="../Itinerary/index.php"<?php if ($currentPage == 'Itinerary') {echo 'id="active"';} ?>>Itinerary</a></li>

       <li ><a href="../Request_Visit/index.php"<?php if ($currentPage == 'Request_Visit') {echo 'id="active"';} ?>>Request a Visit to Your City</a></li>

              <li><a href="../Links/index.php"<?php if ($currentPage== 'Links') {echo 'id="active"';} ?>>Links</a></li>

       <li><a href="../Contact_Us/index.php"<?php if ($currentPage == 'Contact_Us') {echo 'id="active"';} ?>>Contact Us</a></li>

</ul>

try

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.