lukekfreeman on “Using Get Pages for Page List”

Hi all,

I’ve managed to make get pages work for listing a page, however, if there are more than one child page at the same level and one of them has children of its own it will cut off. E.g.:

+ Level one
-+ Level two
-+ Level two
-+ Level three
—+ Level four
+ Level three

Here’s the code. Any help is much appreciated:

<?php
	$pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=DESC');
	$count = 0;
	$ulcount = 0;
	$previous_previous_parent = 0;
	$previous_parent = $page->post_parent;
	$previous_page = $page->ID;
	foreach($pages as $page)
	{
		$parent_page = $page->post_parent;
		if($previous_parent != $parent_page && $previous_page == $parent_page)
			{
				echo '<ul>';
				echo $ulcount++;
			}
		if($previous_parent != $parent_page && $previous_page != $parent_page)
			while($ulcount > 0)
				{
					echo '</ul>';
					echo $ulcount--;
				}
		$content = $page->post_content;
		if(!$content)
			continue;
		$count++;
		$content = apply_filters('the_content', $content);
	?>
		<?php if($ulcount == 0) echo '<hr />'; ?><li>
		<a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a> by <!--<?php echo get_userdata($page->post_author)->user_url; ?>--> <?php echo get_userdata($page->post_author)->display_name; ?> — <?php
		if (get_post_custom_values('Character', $page->ID)==TRUE)
			{
		  $mykey_values = 	get_post_custom_values('Character', $page->ID);
		  foreach ( $mykey_values as $key => $value ) {
		    echo $value;
			echo ', ';
		  }
}
		?><?php echo mysql2date('D, M j, Y H:i a', $page->post_date);  ?></li>
	<?php
	$previous_previous_parent = $previous_parent;
	$previous_parent = $page->post_parent;
	$previous_page = $page->ID;
	}
?>
This entry was posted in Wordpress Templates and tagged custom values, D, gt value, M, parent, PHP, Post, previous page page, Wordpress Templates, Y H. Bookmark the permalink. Both comments and trackbacks are currently closed.