Click here to Skip to main content
12,447,961 members (68,199 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

11.7K views
8 bookmarked
Posted

Dynamic Navigation Menus

, 14 Apr 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Next code demonstrates how to build a simple menu function with the current page high-lighted.index.phpPage - .inactive,...
Next code demonstrates how to build a simple menu function with the current page high-lighted.

index.php
<?php
require_once('menu.php');
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
?>

menu.php
<?php
function menu_item($id, $title, $current)
{
  $class = ($current == $id) ? "active" : "inactive";
?>
  <tr><td class=<?=$class?>>
  <a href="index.php?page=<?=$id?>"><?=$title?></a>
  </td></tr>
<?php
}
function page_menu($page)
{
?>
  <table width="100%">
  <?php menu_item('home', 'Home', $page); ?>
  <?php menu_item('about', 'About', $page); ?>
  <?php menu_item('browse', 'Browse', $page); ?>
  <?php menu_item('download', 'Download', $page); ?>
</table>
<?php
}
?>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

camaki
United States United States
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
Questionphp dynamic menu Pin
chrisdavies2327-Nov-12 4:38
memberchrisdavies2327-Nov-12 4:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160811.3 | Last Updated 14 Apr 2010
Article Copyright 2010 by camaki
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid