<div class="menu">
<ul>
<?php wp_list_pages('exclude=&title_li='); ?>
</ul>
</div>
creates the following output…
<div class="menu">
<ul>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page with Subpages</a>
<ul class="children">
<li><a href="#">Page with another subpage</a>
<ul class="children">
<li><a href="#">subsubpage</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Page 3</a></li>
<li><a href="#">Page 4</a></li>
</ul>
</div>
All pages with children have a ul class="children"
applied. Is it possible to create any function (or any other way) to append a classname to all pages THAT HAVE CHILDREN? In my example above only the “Page with Subpages” and it’s first child-page “Page with another subpage” should have a li.parent
applied.
Is that possible on the serverside? I’m able to do it with javascript, however I wonder if there is a better and cleaner way to do it serverside?
thank you
Phew! Bit more complex than I would’ve liked – if only the filterpage_css_class
passed back$args
it would save a lot of effort (may submit this to trac).Since 3.3 it’s as easy as this!
For those on pre WordPress 3.3, here’s the workhorse:
I’d advise placing the class in your
functions.php
, then it’s available wherever you’d like to use it.To use it, call
wp_list_pages()
like so;I guess there is a more simple solution for that, you could add the following filter in the functions.php file in the theme folder. You don’t have to change anything else.
Hope that helps