Jump to content

how to change template menu link text color for page currently viewed ??


Recommended Posts

Please forgive the ignorance; I am new to php. Could someone please tell me if it possible to do the following with php (or any other server-side scripts):

 

Say you have a left menu that stays the same on every page within in your site. Obviously you would make this menu a template or library item, so that when you edit one version, all the others are updated.

 

Let's say the left menu is the following:

 

Page_1

Page_2

Page_3

 

Now, when I am viewing Page_1, I want the "Page_1" text in the left menu to be red, so that the viewer knows what page they are on. When I click on the left menu link for "Page_2", then I want the "Page_1" text to go back to black and the "Page_2" text to be red.

 

Can it be done?

you can do this by hard-coding the HTML, you can do this with javascript, and you can do it in php. we need to know more info to help you do it in php. but an example would be:

 

if($_SERVER['php_self'] == 'Page_1'){ change color; }

  • 2 weeks later...

Here is so more info to help explain the problem.

 

Let's say I have a website with 3 html pages: Home, About Me, Images. There is an identical menu at the top of each of these pages that looks like this:

Home | About Me | Images

When you click on "Home", it brings you to home.html, when you click on "About Me", it brings you to aboutme.html, etc.

Since this navigation menu is the same on every page, I have made it a library (or template) item. So that if I open the template and change the text "Home" to "Welcome", then when I save it, all 3 of my pages will automatically be updated with the new menu:

Welcome | About Me | Images

 

When I am viewing the home.html page, I want the text "Welcome" in the navigation menu on the top of the page to be bold and red. When I click on "About Me" and go to the aboutme.html, I want the "Welcome" text to go back to it's original size and color and "About Me" to be bold and red.

 

I'd like to do this with a server-side script so that no browser plug-ins are required to view. And I also want to keep my menu as a template, as it frequently changes.

boo_lolly gave you all the code you need.

 

first off, your pages should PROBABLY be .php not .html, unless your server parses PHP on .html extension pages....

 

then, use the code boo gave you right in front of the text, but after the link...

 

if that if statement is true, it will change the font color. and you can add <b> there too. 

 

if that statement is false (ie, that page isnt the current page) the text will be displayed exactly as your CSS or page settings want

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.