Aşağıda bir navigasyon menüsü için üzerinde çalışıyorum bazı kod belirli bir sayfada, eğer uygun sekmesine bir "akım" css sınıfı katacak vardır.
Gerçekten böyle basit bir görevi yapmak için kodu bir sürü gibi görünüyor, çünkü PHP bunu yapmak için daha iyi bir yolu olup olmadığını merak ediyorum? Benim sayfaları da yerine PHP Jquery ile sekmeyi ayarlamak için daha iyi olurdu, bir jquery kütüphanesi zaten yüklenmiş olacak? Takdir herhangi bir ipucu
<?PHP
active_header('page identifier goes here'); //ie; 'home' or 'users.online'
function active_header($page_name)
{
// arrays for header menu selector
$header_home = array('home' => true);
$header_users = array(
'users.online' => true,
'users.online.male' => true,
'users.online.female' => true,
'users.online.friends' => true,
'users.location' => true,
'users.featured' => true,
'users.new' => true,
'users.browse' => true,
'users.search' => true,
'users.staff' => true
);
$header_forum = array('forum' => true);
$header_more = array(
'widgets' => true,
'news' => true,
'promote' => true,
'development' => true,
'bookmarks' => true,
'about' => true
);
$header_money = array(
'account.money' => true,
'account.store' => true,
'account.lottery' => true,
'users.top.money' => true
);
$header_account = array('account' => true);
$header_mail = array(
'mail.inbox' => true,
'mail.sentbox' => true,
'mail.trash' => true,
'bulletins.post' => true,
'bulletins.my' => true,
'bulletins' => true
);
// set variables if there array value exist
if (isset($header_home[$page_name])){
$current_home = 'current';
}else if (isset($header_users[$page_name])){
$current_users = 'current';
}else if (isset($header_forum[$page_name])){
$current_forum = 'current';
}else if (isset($header_more[$page_name])){
$current_more = 'current';
}else if (isset($header_money[$page_name])){
$current_money = 'current';
}else if (isset($header_account[$page_name])){
$current_account = 'current';
}else if (isset($header_mail[$page_name])){
$current_mail = 'current';
}
// show the links
echo '<li class="' . (isset($current_home) ? $current_home : '') . '"><a href=""><em>Home</em></a></li>';
echo '<li class="' . (isset($current_users) ? $current_users : '') . '"><a href=""><em>Users</em></a></li>';
echo '<li class="' . (isset($current_forum) ? $current_forum : '') . '"><a href=""><em>Forum</em></a></li>';
echo '<li class="' . (isset($current_more) ? $current_more : '') . '"><a href=""><em>More</em></a></li>';
echo '<li class="' . (isset($current_money) ? $current_money : '') . '"><a href=""><em>Money</em></a></li>';
echo '<li class="' . (isset($current_account) ? $current_account : '') . '"><a href=""><em>Account</em></a></li>';
echo '<li class="' . (isset($current_mail) ? $current_mail : '') . '"><a href=""><em>Mail</em></a></li>';
}
?>