Well, it’s not bad, though I’d probably have that ALL in a echo statement since I consider opening and closing php like that to be bad coding practice – but again I’m in favor of having <?php and ?> removed from PHP entirely. Would speed it up, plug a number of security holes, make the folks at turdpress have to throw out their entire codebase and maybe try writing code properly for a change…
My approach would probably use inline evaluations like this:
<?php
$currentPage = basename($_SERVER['SCRIPT_FILENAME']);
echo '
<ul>
<li><a href="index.html"',(
$currentPage=='index.html') ? ' class="current"' : ''
),'>Home</a></li>
<li><a href="completedProjects.html",(
$currentPage=='completedProjects.html' ? ' class="current"' : ''
),'>Completed Projects</a></li>
<li><a href="clientele.html",(
$currentPage=='clientele.html' ? ' class="current"' : ''
),'>Clientele</a></li>
<li><a href="keystaff.html",(
$currentPage=='keystaff.html' ? ' class="current"' : ''
),'>Key Staff</a></li>
<li><a href="equipment.html",(
$currentPage=='equipment.html' ? ' class="current" : ''
),'>Equipment</a></li>
<li><a href="contact.html",(
$currentPage=='contact.html' ? ' class="current" : ''
),'>Contact Us</a></li>
</ul>';
?>
Though really that’s a lot of redundant code… I’d probably still build an array first… just to make it a loop and eval for less total code.
$mainMenu=array(
'index.php' => 'Home'
'completedProjects.php' => 'Completed Projects',
'clientele.php' => 'Clientele',
'keystaff.php' => 'Key Staff',
'equipment.php' => 'Equipment',
'contact.php' => 'Contact Us'
);
echo '
<ul id="mainMenu">';
foreach ($mainMenu as $title => $url) {
echo '
<li><a href="',$url,'"',(
$currentPage==$url) ? ' class="current"' : ''
),'>',$title,'</a></li>';
}
echo '
</ul>';
It would also make adding/removing menu items a lot simpler since you would just add the url and title to the array, then let the loop handle the markup.
Could take it even further and use that same array to build your TITLE attribute.
<?php
$siteTitle='Name of the website';
$mainMenu=array(
'index.php' => 'Home'
'completedProjects.php' => 'Completed Projects',
'clientele.php' => 'Clientele',
'keystaff.php' => 'Key Staff',
'equipment.php' => 'Equipment',
'contact.php' => 'Contact Us'
);
$currentPage = basename($_SERVER['SCRIPT_FILENAME']);
$currentTitle=isset($mainMenu[$currentPage]) ? $mainMenu[$currentPage] : '';
if ($currentTitle=='Home') $currentTitle='';
echo '
<title>
',(is_empty($currentTitle) ? '' : $currentTitle.' - '),$siteTitle,'
</title>
</head><body>
<h1>',$siteTitle,'</h1>
<ul id="mainMenu">';
foreach ($mainMenu as $title => $url) {
echo '
<li><a href="',$url,'"',(
$currentPage==$url) ? ' class="current"' : ''
),'>',$title,'</a></li>';
}
echo '
</ul>';
?>
Though that’s treading into starting to build your own CMS… which isn’t necessarily a bad thing given the quality of most of the off the shelf ones.