PHP – WordPress – List Sub Pages of Current Page

The given PHP example list the sub pages of a current page in WordPress.

Code Example:
<?php
function list_sub_pages() {
	global $wp_query;
	if( empty($wp_query->post->post_parent) ) {
		$parent = $wp_query->post->ID;
		echo "<h3>".get_the_title($parent)."</h3>";
	} else {
		$parent = $wp_query->post->post_parent;
		echo "<h3><a href='".get_permalink($parent)."'>".get_the_title($parent)."</a></h3>";
	}
	echo '<ul>';
	wp_list_pages("title_li=&child_of=$parent" );
	echo '</ul>';
}
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *