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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.