Jump to content

class="active" Help


nay27uk

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/262235-classactive-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/262235-classactive-help/#findComment-1345209
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.