Question: php include + id current

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Question: php include + id current

Post by C_Calav »

hi Guys,

i am using a php include for a menu across about 20 pages.

is there a way i can still use the php include and be able to show some how what page they are on?

in the past i have used css and id=current but that was with the menu hard coded on everypage.

thanks guys
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

if you're doing index.php?page=currentpage. simply go

Code: Select all

$page=$_GET['page']; 
switch ($page)
{
   case"main":
    echo "Home page";
    break;
}
something like that? :-D
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

Thanks for the reply!

hmmm.. can you explain please a little more please?

im not sure im getting what your saying, my bad :?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

are you wanting to display what page a user is on to them? or store it in a database? appearantly I mis-understood you...
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

at the moment my navigation.php is just all <li> list elements. i want to add id=current (css) to the page they are on so if you look at the navigation being displayed it will show that link in the navagtion in a different colour.

but to do that i would have to hard code the navagation into every page and on each different page add id=current to a <li>

was wondering if there is a way i can keep my php include navagation.php and still have this effect.

sorry if i am not making sense. does this help?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

eh.post two of your pages..lemme see..
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

i think i have got it now.

Code: Select all

if ($pageis=="home") 
{ 
print('<li id=\"current\">Home</li>'); 
} 
else 
{ 
print('<li>home</li>'); 
}
something like this in my navagation.php?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

need to use a switch case so you don't have to do a bunch of if statements :-D
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

yes! thanks for that.. i proberly would have had 'if' statements for africa..

thanks for your help
Post Reply