Return to Snippet

Revision: 40477
at February 2, 2011 22:03 by louisdedecker


Initial Code
to test it, put this in "wp-content/themes/[theme name]/header.php"


//-------------------------------------------------------------
// pagesRecursive
//   lists pages of a WP recursively
//-------------------------------------------------------------
function pagesRecursive($parentId, $lvl){ 
	$args=array('child_of' => $parentId, 'parent' => $parentId);
	$pages = get_pages($args); 
	if ($pages) {
		$lvl ++;
		foreach ($pages as $page) {
			print "<div style='margin-left:".($lvl * 30)."; border:solid 1px #000; margin-bottom:10px; '>";
			print $page->ID."<br>";
			print $page->post_date."<br>";
			print $page->post_title."<br>";
			print $page->post_content."<br>";
			print "</div>";
			pagesRecursive($page->ID, $lvl);
		} 
	}
}
pagesRecursive(20, 0);

Initial URL

                                

Initial Description
this is pretty useful if you want to use the wordpress blog system to feed a custom application/site of yours

Initial Title
Wordpress recursive page listing

Initial Tags
wordpress

Initial Language
PHP