Jump to content


Photo

PHP Include Menu and CSS


  • Please log in to reply
2 replies to this topic

#1 loyalblue

loyalblue

    Forum Newcomer

  • Members
  • Pip
  • 2 posts

WDF Reputation

0
Neutral

Posted 16 February 2012 - 08:25 PM

Hi Folks,

Just a quick question, hopefully somebody can clear this up for me please.

I have my navigation menu in a php include file being expressed in each page.
<?php include("includes/menu.php"); ?>


I also have my menu styled in my CSS sheet. However, the problem lies on the link being 'active'. Meaning, when I'm at the 'Home' page then the 'Home' button should be highlighted and so on etc.

Now, how can this be done using CSS so that the current page corresponds with the certain button, and thus highlight that button?...

I think I know one way, but I failed doing it as I'm not quite sure / certain how to lay it in the stylesheet.

--- Give the body tag of each individual PHP page a unique ID, for example: body id="home" for the home page. Furthermore, give each li anchor link in the php include file add the appropriate unique ID <li><a href="home.php" id="home">Home</a></li>. Then, when it comes to the CSS I'm a little sticky ??

That way, each page / body will have it's own unique id and thus each link will have it's own unique id for the current page to correspond with the CSS, and each active link can be altered and differ if wanted.

Thanks.

Blackfoot Hosting

#2 zed

zed

    not a mod

  • Privileged
  • PipPipPipPipPipPip
  • 5,738 posts

WDF Reputation

789
Excellent
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 February 2012 - 08:30 PM

If I understand correctly then why not use your php to detect the page that is open in the browser and then conditionally class they button styling based in that?

#3 loyalblue

loyalblue

    Forum Newcomer

  • Members
  • Pip
  • 2 posts

WDF Reputation

0
Neutral

Posted 17 February 2012 - 11:24 AM

How do you mean?

Like a PHP Syntax in the head section of each page..

<?php $page = 'Home';?>


And then in the menu include perhaps an IF or ELSE command?

Thanks.

Edited by loyalblue, 17 February 2012 - 11:25 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users