<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Brendan Nee &#187; php</title>
	<atom:link href="http://blog.bn.ee/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bn.ee</link>
	<description></description>
	<lastBuildDate>Fri, 13 Jan 2012 11:00:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>List pages in wordpress into a PHP Array</title>
		<link>http://blog.bn.ee/2008/04/10/list-pages-in-wordpress-into-a-php-array/</link>
		<comments>http://blog.bn.ee/2008/04/10/list-pages-in-wordpress-into-a-php-array/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 10:04:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.bnee.com/?p=161</guid>
		<description><![CDATA[Update: Thanks to Joost in the comments for suggesting the use of get_pages() to accomplish the same thing as what I posted below. He posted the example: $pages = get_pages(‘child_of’ => [[THE PARENT ID]], ’sort_order’ => ‘ASC’); foreach ($pages as $page) { // Do your thang } This seems much better than what I had [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> Thanks to Joost in the comments for suggesting the use of <a href="http://codex.wordpress.org/Function_Reference/get_pages">get_pages()</a> to accomplish the same thing as what I posted below.  He posted the example:</p>
<pre><textarea style="border:1px solid #999;word-wrap:break-word;width:500px;height:100px;">
$pages = get_pages(‘child_of’ => [[THE PARENT ID]], ’sort_order’ => ‘ASC’);
foreach ($pages as $page) {
  // Do your thang
}
</textarea></pre>
<p>This seems much better than what I had previously used, but for reference, my old post is below:</p>
<p>I spent some time figuring out how to get the <a href="http://codex.wordpress.org/wp_list_pages">wordpress wp_list_pages function</a> to return the results as a PHP array of URLs and page names.  There wasn&#8217;t an obvious way to do this and searching google did not yield anything particularly useful.  The wp_list_pages function has an &#8220;echo&#8221; parameter which when set to 0 returns a list of links as a string.  That won&#8217;t help much if you want it as an array with links and page names.</p>
<p>I ended up writing a short script that will query wordpress for the name and URL of all of the subpages of a specified page.  This could be used to make a function that formatted a list of pages a particular way (like making the list wrap into two or more columns).  Its nothing fancy, but perhaps it can help other wordpressers who are looking for something similar.</p>
<blockquote><p>
&lt;?php<br />
$querystr = &#8220;SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = &#8216;publish&#8217; AND $wpdb->posts.post_type = &#8216;page&#8217; AND $wpdb->posts.post_parent = [[Parent Page ID]] ORDER BY $wpdb->posts.post_title ASC&#8221;;</p>
<p>$pageposts = $wpdb->get_results($querystr, OBJECT);</p>
<p>if ($pageposts):<br />
	foreach ($pageposts as $post):<br />
	setup_postdata($post);<br />
		// Add your own logic or formatting here<br />
		?><br />
		&lt;a href=&#8221;&lt;?php the_permalink() ?>&#8221; title=&#8221;Permanent Link to &lt;?php the_title(); ?>&#8221;>&lt;?php the_title(); ?>&lt;/a><br />
	&lt;?php endforeach;<br />
	else :<br />
		echo &#8216;Not Found&#8217;;<br />
endif;<br />
?>
</p></blockquote>
<p>Where [[Parent Page ID]] is the id number of the parent page you would like to get children from.  If you want all pages included, don&#8217;t include this parameter.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bn.ee/2008/04/10/list-pages-in-wordpress-into-a-php-array/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 16/23 queries in 0.024 seconds using disk: basic

Served from: blog.bn.ee @ 2012-02-05 17:55:31 -->
