Jump to content

How do I show the active page in my navigation?


expandmind

Recommended Posts

Hello,

 

header.tpl >> In my navigation I have a list of pages:

 

<ul id="mainmenu">

<li class="active"><a href="/home">Home</a></li>

<li><a href="/page1">/Page2</a></li>

<li><a href="/page/page2">Page2</a></li>

</ul>

 

How do I go about creating something that automatically changes the active page to have the class 'active' assigned to it? - Active links on my main menu.

 

Thank you in advance.

Link to comment
Share on other sites

We did this on our whmcs based site (http://www.simplexwebs.com) using smarty {if} statements and a bit of php.

 

In each of the pages, we created a smarty variable called 'category' and assigned it the page name eg.

 

$category = "hosting";
initialiseClientArea($pagetitle,$pageicon,$breadcrumbnav);
$smartyvalues["category"] = $category; 

 

or

$category = "aboutus";
initialiseClientArea($pagetitle,$pageicon,$breadcrumbnav);
$smartyvalues["category"] = $category; 

 

then in the header.tpl we used:

 

	{if $category eq NULL}
	{php}
		$basename=pathinfo($_SERVER["PHP_SELF"]);
		$basename=$basename["basename"];
		if ($basename=="index.php")
		{
		echo(' SHOW HOMEPAGE ACTIVE ');
                       }
		else
		{
                         echo(' SHOW ACTIVE WHMCS PAGES E.G SUPPORT, KNOWLEDGEBASE ETC. ');
{/php}
{elseif  $category eq sharedhosting}
CODE FOR NAV WITH SHARED HOSTING ACTIVE
{/if}

 

Just repeating the elseif for however many categories you have. This might seem a little long winded, but its the only decent option I found that works.

Link to comment
Share on other sites

Hello,

 

I think there is a much easier way to this, with help from Mat WHMCS Support - Thank you,

 

" The variable $filename contains the current page the user is on so in the template files, you could for example do something like this:

 

<li{if $filename eq "announcements"} class="active"{/if}><a href="announcements.php">Announcements</a></li>

 

And with that, if the page was announcements, that menu option would be active. You can do the same for other page names aswell."

 

regards,

Alex

Link to comment
Share on other sites

Hello,

 

I think there is a much easier way to this, with help from Mat WHMCS Support - Thank you,

 

" The variable $filename contains the current page the user is on so in the template files, you could for example do something like this:

 

<li{if $filename eq "announcements"} class="active"{/if}><a href="announcements.php">Announcements</a></li>

 

And with that, if the page was announcements, that menu option would be active. You can do the same for other page names aswell."

 

regards,

Alex

 

I see a issue with this however, some pages have the same filename, but different actions. So while this is easier... its also useless.

Edited by EricHamby
Link to comment
Share on other sites

I see a issue with this however, some pages have the same filename, but different actions. So while this is easier... its also useless.

 

using {if $filename eq "clientarea" and $smarty.get.action eq "details"} you can show as active the pages with same filename, but different actions..

 

Thank you,

Alex

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated