<?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>Twenty3design - Web design and Development &#187; Wordpress</title>
	<atom:link href="http://www.twenty3design.co.uk/category/blog/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.twenty3design.co.uk</link>
	<description>Web design and development</description>
	<lastBuildDate>Tue, 24 Aug 2010 20:25:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Getting page Grandparent in Wordpress</title>
		<link>http://www.twenty3design.co.uk/blog/getting-page-grandparent-in-wordpress/</link>
		<comments>http://www.twenty3design.co.uk/blog/getting-page-grandparent-in-wordpress/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 20:54:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.twenty3design.co.uk/?p=926</guid>
		<description><![CDATA[Ok, just a quick wordpress blog incase anyone has ever had this problem and I found solutions a little on the thin side.
On a site I&#8217;m making for a client they have various menu levels and in one place they needed to return the links from the second level no matter what level below that [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, just a quick wordpress blog incase anyone has ever had this problem and I found solutions a little on the thin side.<span id="more-926"></span></p>
<p>On a site I&#8217;m making for a client they have various menu levels and in one place they needed to return the links from the second level no matter what level below that in the tree you were on.  Basically treating the second level as if it were the top level.  If it <em>was</em> the top level then Wordpress has a nice handy function built in for us, but for this there is a bit more coding involved.</p>
<p>Getting your page parent id is fairly simple:</p>
<p><code>if($post-&gt;post_parent) {<br />
$parent_id = $post-&gt;post_parent;<br />
}</code></p>
<p>so to take this a step further and find out if this parent had a parent you need to place the following function in your &#8220;functions.php&#8221; file in your theme:</p>
<p><code>function is_third_level($parent_id) {<br />
global $wpdb;<br />
$grand_parent = $wpdb-&gt;get_var("SELECT post_parent FROM $wpdb-&gt;posts WHERE ID = '".$parent_id."' AND post_type = 'page'");<br />
if ($grand_parent) {<br />
return true;<br />
} else {<br />
return false;<br />
}<br />
}</code></p>
<p>Here we are checking the database for the parent of the ID we&#8217;ve passed in and returning if there is anything, thus letting us know if there is another parent or not. (I&#8217;m just returning true/false, but you could return the ID of the parent if you wanted.)</p>
<p><code>if($post-&gt;post_parent) {<br />
$parent_id = $post-&gt;post_parent;<br />
if (!is_third_level($parent_id)) {<br />
$pages = get_pages("sort_order=asc&amp;sort_column=menu_order&amp;child_of=".$post-&gt;ID);<br />
echo "&lt;h2&gt;".get_the_title($post-&gt;ID)."&lt;/h2&gt;";<br />
} else {<br />
$pages = get_pages("sort_order=asc&amp;sort_column=menu_order&amp;child_of=".$parent_id);<br />
echo "&lt;h2&gt;".get_the_title($parent_id)."&lt;/h2&gt;";<br />
}<br />
}</code></p>
<p>Once I get my response from the database I can then either print the title of the current page, or the one above.</p>
<p>Hope this helps anyone who has been stuck in a similar situation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twenty3design.co.uk/blog/getting-page-grandparent-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
