Thread Starter
jamble
(@jamble)
Sorry for the bump but I wonder if anyone is able to help on this one?
Thanks!
Super easy man, by default WordPress assigns classes to current pages li items, and than changes that class if the current page has a parent.
For current page, the class is ‘current_page_item’
If that page has a parent, it will change to ‘current_page_parent’ and if you have dynamic subnav available in your theme, the link of the page you’re on will include the ‘current_page_item’ as a class. So using CSS you can style those links to change with that class. Hope that makes sense.
You can read all about it (and how to dynamically show your subpages) here – http://codex.wordpress.org/Template_Tags/wp_list_pages
Thread Starter
jamble
(@jamble)
Thanks for the post, unfortunately it’s not so super easy ..
If you take a look at the source on the “our products” page and also the “riders blogs” for example, it doesn’t add the current_page_item class to the navigation list or add any other class that is current to the page I’m on.
For example, here is the nav list source for the “riders blogs” index page
<li class=”page_item page-item-15″>Home
<li class=”page_item page-item-17″>Our products
<li class=”page_item page-item-18″>Stockists
<li class=”page_item page-item-19″>Riders blogs
<li class=”page_item page-item-20″>About us
<li class=”page_item page-item-35″>Links
<li class=”page_item page-item-21″>Contact
<li class=”page_item page-item-47″>Our team
<li class=”page_item page-item-22″>Latest news
As you can see, there is no class on the list I can use to apply the current page style. It’s strange because if you look on a page such as “about us” then the class current_page_item does appear and it works on there but not some of the other pages.
I believe this is a new feature in WP 2.3.3 – what version are you running?
Thread Starter
jamble
(@jamble)
I’m running 2.3.3 at the moment, everything up to date etc.
I just thought I’d probably need to create some sort of dynamic code in the header for the navigation to assign a class or id on the list based on page/category id but I’m not sure how to do this and the dynamic tags help doesn’t really say how to do it in this way.
that post explains everyting you need to add nav dynamically:
for main nav:
<ul>
<?php
wp_list_pages('title_li='); ?>
</ul>
for sub pages:
<ul>
<?php
wp_list_pages('title_li=&child_of='.$post->ID.'&show_date=modified
&date_format=$date_format'); ?>
</ul>