Page 1 of 1
PHP Menu help
Posted: Sun Jan 25, 2009 12:19 pm
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!
Thanks,
Tom.
Re: PHP Menu help
Posted: Sun Jan 25, 2009 5:34 pm
by Deuce
use <strong> or post some code?
Re: PHP Menu help
Posted: Sun Jan 25, 2009 5:49 pm
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.
Re: PHP Menu help
Posted: Mon Jan 26, 2009 2:24 am
by papa
Is it a dynamic menu ?
Re: PHP Menu help
Posted: Mon Jan 26, 2009 11:59 am
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...
Re: PHP Menu help
Posted: Mon Jan 26, 2009 12:10 pm
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;
}
Re: PHP Menu help
Posted: Mon Jan 26, 2009 1:07 pm
by tomsace
Wow, thanks alot. I have managed to get this working perfectly!!
Nice work

Re: PHP Menu help
Posted: Mon Jan 26, 2009 1:56 pm
by John Cartwright
I forgot to mention you should run $_SERVER['REQUEST_URI'] through basename() to rid it of any additional query string.