Skip to content

Instantly share code, notes, and snippets.

@inerds
Last active August 29, 2015 14:11
Show Gist options
  • Save inerds/54262cfb39e54d268ca2 to your computer and use it in GitHub Desktop.
Save inerds/54262cfb39e54d268ca2 to your computer and use it in GitHub Desktop.
List subpages of parent page (with parent page title) in Wordpress
<?php if ( is_page() ) { ?>
<?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) { ?>
<h4>
<?php
$parent_link = get_permalink($post->post_parent);
$parent_title = get_the_title($post->post_parent);
?>
<a href="<?php echo $parent_link; ?>" ><?php echo $parent_title; ?></a>
</h4>
<ul class="subpages">
<?php echo $children; ?>
</ul>
<?php } } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment