There is an easier way in selecting the current link using PHP.
If you change the body id dinamically, you can change the links with CSS this way:
body#home a.home, body#page a.page, body#anything a.anything { font-weight: bolder; color: yellow; }
And you can keep the menu without PHP, as simple as this example:
<ul class="menu"> <li><a href="/" class="home">Home</a></li> <li><a href="/page/" class="page">Home</a></li> <li><a href="/anything/" class="anything">Home</a></li> </ul>
See? No need to put "current" on each link. Let the CSS do the work for you. --Alenonimo 09:09, 27 Aug 2007 (UTC)
Template Tags/wp_list_pages styles the current page link with an extra class: current_page_item. --MDAWaffe - Talk (forgot to sign, sorry!)
This is great, but it looks like this "current page" issue turned up in a wp_list_pages. Can we include this information AND how to stylize this same technique for categories, since that is what is usually the most requested. Not the Pages feature so much as what category the post is in. A kind of breadcrumb effect. Will this technique work for that?
This is excellent information. Thanks for putting it together! Lorelle 16:14, 17 Mar 2005 (UTC)
I'll have to research a little more and see what I can do. I'm sure it'll work, but I don't exactly know how at the moment. I'll work on expanding it to do categories. Anyone else is welcome to help me.
Well, with just a little reasearch, it looks like this won't work with categories; at least not with category lists built with list_cats because I couldn't see a way to customize the list items it outputs to include the unique id
's. --Avenir 16:58, 17 Mar 2005 (UTC)
Can't this be done with Template Tags/wp_list_pages#CSS Styles? (see first comment on this discussion page). Perhaps I am missing something? --MDAWaffe - Talk 10:15, 24 Mar 2005 (UTC)
I added a second way of going about all this, one that lets all the CSS stay in one place: the CSS document. This is the method I use on my site and it allows for a bit more than the previous method.
This has seemed to focus on creating a dynamic menu when working with Pages, but I tried to bring in how to make a blog menu dynamic as well. I think this should focus on the dynamic menu creation and not the specific application to Pages.
I tried to keep the working example simple, but then dropped a big chunk of code at the end that has a few different scenarios in it, allowing visitors to see some possibilities. What needs to change? Did I just complicate things too much? Should we have two pages, one that shows how to implement these menus for a site using Pages and the other for a site using the regular blog features of WP? Todd 16:42, 12 Aug 2006 (GMT)