Menu PHP block

This is a simple PHP block taken from the main Template Blocks website. A good feature is that is automatically defines the selected tab based on the URL the visitor is viewing:

<?php
 
$links = array( 'Home' => '/',
                'Features' => '/features.html',
                'Demo' => '/demo.html',
                'Download' => '/download.html',
                'Support' => '/support/',
                'About' => '/about.html'
               );
 
echo '  <ul id="toplinks">';
 
foreach( $links as $key => $value ){
  $selected = ($_SERVER['REQUEST_URI'] == $value) ? ' class="selected"' : '';
  echo '<li><a href="' . $value . '"' . $selected . '><span>' . $key . '</span></a></li>';
}
 
echo '  </ul>';
 
?>

Just replace the array at the top the with your URL list and menu titles. You might also need to make some modifications in the markup that is generated…

Leave a Reply