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