nay27uk Posted May 8, 2012 Share Posted May 8, 2012 Hi all I am new here and looking for some help, I am also not a PHP coder and learning as I go. My problem is this I have a script and have a header.php and global_header.tpl amongst all the other files that come in the script, I have a tabed navigation in global_header.tpl that I want to set to class="active" depending on what page is being viewed. I have spent all last night and all of today going through google and yahoo trying all diferent bits of code but absolutly nothing works. At the moment I have a file I made from some code found on google that I placed in its own .hph file named activetabs.php,I have included this in header.php using include 'activetabs.php'; In activetabs.php I have <?php if ($_SERVER["REQUEST_URI"] != '/browse.php') { $tab1 = 'none'; } else { $tab1 = 'active'; } $template->assign_vars(array( 'TAB1' => $tab1, )); ?> testing only but againe it wont work. If I change the above code to <?php if ($_SERVER["REQUEST_URI"] == '/browse.php') { $tab1 = 'none'; } else { $tab1 = 'active'; } $template->assign_vars(array( 'TAB1' => $tab1, )); ?> the tab becomes active but stays active. Could any of you either show me how to get that code working or kindly provide me some working code. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/262235-classactive-help/ Share on other sites More sharing options...
The Letter E Posted May 14, 2012 Share Posted May 14, 2012 Hi all I am new here and looking for some help, I am also not a PHP coder and learning as I go. My problem is this I have a script and have a header.php and global_header.tpl amongst all the other files that come in the script, I have a tabed navigation in global_header.tpl that I want to set to class="active" depending on what page is being viewed. I have spent all last night and all of today going through google and yahoo trying all diferent bits of code but absolutly nothing works. At the moment I have a file I made from some code found on google that I placed in its own .hph file named activetabs.php,I have included this in header.php using include 'activetabs.php'; In activetabs.php I have <?php if ($_SERVER["REQUEST_URI"] != '/browse.php') { $tab1 = 'none'; } else { $tab1 = 'active'; } $template->assign_vars(array( 'TAB1' => $tab1, )); ?> testing only but againe it wont work. If I change the above code to <?php if ($_SERVER["REQUEST_URI"] == '/browse.php') { $tab1 = 'none'; } else { $tab1 = 'active'; } $template->assign_vars(array( 'TAB1' => $tab1, )); ?> the tab becomes active but stays active. Could any of you either show me how to get that code working or kindly provide me some working code. Thanks in advance You can try something like this: <?php $self = explode('/', $_SERVER['PHP_SELF']); $currentpage = $self[1]; $currentpage = explode('.', $currentpage); $$currentpage[0] = 'class="active"'; ?> <a href="browser.php" <?=@$browser?>>Browser</a> <a href="home.php" <?=@$home?>>Home</a> <a href="contact.php" <?=@$contact?>>Contact</a> That's a very basic untested example of how you could achieve what you want. Quote Link to comment https://forums.phpfreaks.com/topic/262235-classactive-help/#findComment-1345209 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.