Jump to content

Archived

This topic is now archived and is closed to further replies.

esahp

Bit of PHP help

Recommended Posts

I'm not quite sure how to do this or exactly how to explain it. There is a peice of code I want dynamically placed around a certin menu item when that menu item is clicked. The layout is setup where the navigation looks like tabs at the top, and <li id="first" class="active"></li> will make that tab look like its the 'active' one.
I have the navigation in nav.php which is included with include();. I'd like for the tab I click on to appear active on that page.

Hope I've made this clear enough..
[i]nav.php[/i]
[code]
<li id="first" class="active"><a href="index.php">Main</a></li>
<li><a href="staff.php">Staff/Servers</a></li>
<li><a href="tos.php">TOS</a></li>
<li><a href="aup.php">AUP</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
[/code]

Share this post


Link to post
Share on other sites
This code should give you an idea of how it's done.

[code]<?php
$links = array(
'index' => 'Main',
'staff' => 'Staff/Servers',
'tos' => 'TOS',
'aup' => 'AUP',
);

$current_page = empty($_GET['page']) || !key_exists($_GET['page'],$links) ? 'index' : $_GET['page'];

echo <<<EOF
<style type="text/css">
.active {
font-weight: bold;
}
</style>
<ul>

EOF;
foreach($links as $link_key => $link_text)
{
if($current_page == $link_key)
{

}
$extra = $current_page == $link_key ? " class='active'" : null;
echo "\t<li{$extra}><a href='?page={$link_key}'>{$link_text}</a></li>\n";
}
echo "</ul>\n";
?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.