Jump to content

Bit of PHP help


esahp

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]
Link to comment
https://forums.phpfreaks.com/topic/22673-bit-of-php-help/
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]
Link to comment
https://forums.phpfreaks.com/topic/22673-bit-of-php-help/#findComment-101937
Share on other sites

Archived

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

×
×
  • Create New...

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.