Posted By

1man on 04/25/07


css php include style navigation

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Simple PHP Navigation

 / Published in: PHP


Very simple navigation. Style the id using CSS. Allows you to highlight the current page with CSS.

  1. //Place this in an include
  2. <ul>
  3. <li><a href="../index.php" <?php if($thisPage == 'home') echo 'id="here"';?> >Home</a></li>
  4. <li><a href="../page1/index.php" <?php if($thisPage == 'page1') echo 'id="here"';?> >Page 1</a></li>
  5. <li><a href="../page2/index.php" <?php if($thisPage == 'page2') echo 'id="here"';?> >Page 2</a></li>
  6. <li><a href="../page3/index.php" <?php if($thisPage == 'page3') echo 'id="here"';?> >Page 3</a></li>
  7. </ul>
  9. //This php goes inside each page, notice the variable
  10. <?php
  11. $thisPage = 'home';
  12. include('includes/');
  13. ?>

Report this snippet  


RSS Icon Subscribe to comments
Posted By: tylerhall on April 25, 2007

An easier and less cumbersome method is to do it all with CSS. With the code below, all you have to do is switch out the class using PHP (no messy if statements required within the HTML).

<style type="text/css" media="screen">
    body.page1 li.page1,
    body.page2 li.page2,
    body.page3 li.page3 { style info here }

<body class="page2">
    <li class='page1'><a href='#'>Page 1</a></li>
    <li class='page2'><a href='#'>Page 2</a></li>
    <li class='page3'><a href='#'>Page 3</a></li>

You need to login to post a comment.