We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Ballyhoo


Posted By

1man on 04/25/07


Tagged

css php include style navigation


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

vali29


Simple PHP Navigation


Published in: PHP 


URL: http://alistapart.com/articles/keepingcurrent/

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>
  8.  
  9. //This php goes inside each page, notice the variable
  10. <?php
  11. $thisPage = 'home';
  12. include('includes/navigation.inc.php');
  13. ?>

Report this snippet 

Comments

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 }
</style>

<body class="page2">
...
<ul>
    <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>
</ul>

You need to login to post a comment.