function show_subpages() {
global $post;
$subpages = wp_list_pages( array(
'echo' =>0,
'title_li' =>'',
'depth' =>2,
'link_before' => '— ',
'child_of' => ( $post->post_parent == 0 ? $post->ID : $post->post_parent),
'exclude' => ( $post->post_parent == 0 ? '' : $post->ID)
));
if ( !empty($subpages) ) {
echo '<ul id="subpages" class="wrapper">';
echo $subpages;
echo '</ul>';
}
}
wp_list_pages
supports an exclude
parameter. In the above, I’ve simply added 'exclude' => ( $post->post_parent == 0 ? '' : $post->ID)
to the parameter array.
It works analogous to the way you are already feeding values to child_of
:
If the post does not have a parent, we feed exclude
an empty string. If it has one, we feed it the current post ID.