How do I add class to sidebar on $_GET
I got a problem to get correct class to my sidebar.
function sidebar_class($var)
{
if (isset($_GET['page']) == $var )
echo ' class="selected"';
}
My URL will looks like
http://domain.com/index.php?go=users
http://domain.com/index.php?go=settings
http://domain.com/index.php?go=backup
My sidebar
<ul>
<li<?php sidebar_class('users'); ?>><a href='index.php?go=users'>Users</a></li>
<li<?php sidebar_class('settings'); ?>><a href='index.php?go=settings'>Settings</a></li>
<li<?php开发者_运维问答 sidebar_class('backup'); ?>><a href='index.php?go=backup'>Backup</a></li>
</ul>
Now all my sidebar class being <li class="selected">
. How to fix it?
wrong function... try:
function sidebar_class($var)
{
if (isset($_GET['go']) && $_GET['go'] == $var )
echo ' class="selected"';
}
Do you want to check value of go instead of page. right?
function sidebar_class($var)
{
if (isset($_GET['go']) == $var )
echo ' class="selected"';
}
精彩评论