<?php
if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children) {
$parent_title = get_the_title($post->post_parent);?>
<li><a href="<?php echo get_permalink($post->post_parent) ?>"><?php echo $parent_title;?></a></li>
<?php echo $children; ?>
<?php } ?>
The code above lists the parent and all child pages in a list.
Parent Page
Child Page
Child Page class=”active”
Child Page
Child Page
I would like to add a class of “active” to the currently active page. Any help is greatly appreciated. Thanks
To look for a specific page and add an active class to it, you can try using is_page and define the URL/slug of the page.
You can easily add active and other classes by checking the
$post->post_title
against the$item->title
I am using this myself and stripping out the wrapping container, the ul, and the li tags so that I have just a link. See example below.