This code works well to display child pages of the parent page while viewing both the parent page and child page. It doesn’t apply the current_page_item
CSS class to the parent while viewing it (and only it, not interested in it being applied while on the children) – any suggestions?
<ul class="subpages">
<?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 } ?>
</ul>
If I understand what you want, it is trickier than it should be to get it working.
You have to get a list of all of your pages and pass them in the
include
parameter. The basic technique is listed in the Codex. The above is nearly a copy, in fact.That will give you
current_page_ancestor
on all ancestor pages andcurrent_page_parent
on the immediate parent only. That should be sufficient.If you notice I have included the top-level parent in the page list. Your code only does that sometimes. I don’t know if that is by design or not, but I included it. You should be able to add or remove that page to match whatever logic you need.
Solution for your problem
Try it
1.get_page()
2.get_pages()
3.Note:Remove css style at top of my code when your test complete and apply your own css code.