Return to Snippet

Revision: 36963
at December 1, 2010 21:18 by eggchops


Initial Code
<?php

// get parent ID
function getTopParentPostName($myid)
{
	$mypage = get_page($myid);

	if ($mypage->post_parent == 0)
	{
		return $mypage->post_name;
	}
	else
	{
	        return getTopParentPostName($mypage->post_parent);
	}
}

// get ID of parent from slug
function get_ID_by_slug($page_slug) {
	$page = get_page_by_path($page_slug);
	if ($page) {
		return $page->ID;
	} else {
		return null;
	}
}

$args = array(
		'echo'         => 1,
		'title_li'     => '',
		'child_of'     => get_ID_by_slug(getTopParentPostName($post->ID)),
		'sort_column'  => 'menu_order, post_title'); 

?>
<?=wp_list_pages( $args );?>

Initial URL

                                

Initial Description
Use getTopParentPostName() to get the parent slug. Then use get_ID_by_slug() to get the ID of it. The use wp_list_pages() to display the child pages :)

Initial Title
Get parent name from post->ID and display list of child pages from that.

Initial Tags

                                

Initial Language
PHP