PHP Menu help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

PHP Menu help

Post by tomsace »

Hey,

On my website it lists a bunch of products I have for sale. I have made a link so users can edit how the list is shown (list or thumbnails). I want to know how to edit the font on my list so when the user is on list, the font is bold, then when they click thumbnail the text will change to be bold on the thumbnails text etc... I have been trying but no success! :banghead:

Thanks,
Tom.
Deuce
Forum Newbie
Posts: 12
Joined: Sun Jan 25, 2009 5:23 pm

Re: PHP Menu help

Post by Deuce »

use <strong> or post some code?
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

Re: PHP Menu help

Post by tomsace »

I use a menu.php as the main menu on all pages and use the include code on all other pages.
I want to edit the menu.php basically so when the user clicks a page, the page they are on is bold in the menu.

Tom.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: PHP Menu help

Post by papa »

Is it a dynamic menu ?
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

Re: PHP Menu help

Post by tomsace »

Its just a basic html menu. Not dynamic, no.
Its layed out in a table,

E.g.
<table><tr><td>
Home
</td></tr><tr><td>
Link 1
</td></tr><tr><td>
Link 2
</td></tr></table>

etc...
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: PHP Menu help

Post by John Cartwright »

Typically you would use a list in this case. A table is not neccesary, and harder to style in this case as well. Reguardless, if you want to do this on the server side then it will be a matter of looping your menu elements and checking whether it matches the current url. I just threw in $_SERVER['REQUEST_URI'] but you may need to parse it differently depending on your navigational structure.

A simple example:

Code: Select all

$menu = array(
   'Home' => '/home.php',
   'Register' => '/register.php',
   'FAQ' => '/faq.php'
);
 
foreach ($menu as $itemname = $itemurl) {
   echo '<li '. ($itemurl == $_SERVER['REQUEST_URI'] ? 'class="menu-selected"' : '') .'>'. $itemname .'</li>'; 
}
 
and add a css class

Code: Select all

.menu-selected {
   font-weight: bold;
}
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

Re: PHP Menu help

Post by tomsace »

Wow, thanks alot. I have managed to get this working perfectly!!
Nice work :lol:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: PHP Menu help

Post by John Cartwright »

I forgot to mention you should run $_SERVER['REQUEST_URI'] through basename() to rid it of any additional query string.
Post Reply