<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Is current WordPress page in the hierarchy of some other?</title>
	<atom:link href="http://inchoo.net/wordpress/hierarchy-identification-child-parent-page/feed/" rel="self" type="application/rss+xml" />
	<link>http://inchoo.net/wordpress/hierarchy-identification-child-parent-page/</link>
	<description>Magento Design and Magento Development Professionals - Inchoo</description>
	<lastBuildDate>Fri, 10 Feb 2012 05:35:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Coen Jacobs</title>
		<link>http://inchoo.net/wordpress/hierarchy-identification-child-parent-page/comment-page-1/#comment-3272</link>
		<dc:creator>Coen Jacobs</dc:creator>
		<pubDate>Sat, 12 Sep 2009 11:12:46 +0000</pubDate>
		<guid isPermaLink="false">http://inchoo.net/?p=156#comment-3272</guid>
		<description>I think there is a far more easy way doing this. Take a look at &lt;a href=&quot;http://coenjacobs.net/blog/page-ancestors-easy-wordpress&quot; rel=&quot;nofollow&quot;&gt;my example with get_post_ancestors()&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>I think there is a far more easy way doing this. Take a look at <a href="http://coenjacobs.net/blog/page-ancestors-easy-wordpress" rel="nofollow">my example with get_post_ancestors()</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arit</title>
		<link>http://inchoo.net/wordpress/hierarchy-identification-child-parent-page/comment-page-1/#comment-1337</link>
		<dc:creator>Arit</dc:creator>
		<pubDate>Sun, 15 Mar 2009 23:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://inchoo.net/?p=156#comment-1337</guid>
		<description>hi,
that seems exactly what i&#039;m looking for. though i&#039;m not familar with php, i&#039;m wondering how to include it into my code.
i want to change an image according to the ancestor page
for the example above: image#1 for all childpages (and grandchildpages etc.) of Main Page#1, and show image#2 to for all childpages (and grandchildpages etc.)of Main Page#2 and so on
may anybody help me?
thanks</description>
		<content:encoded><![CDATA[<p>hi,<br />
that seems exactly what i&#8217;m looking for. though i&#8217;m not familar with php, i&#8217;m wondering how to include it into my code.<br />
i want to change an image according to the ancestor page<br />
for the example above: image#1 for all childpages (and grandchildpages etc.) of Main Page#1, and show image#2 to for all childpages (and grandchildpages etc.)of Main Page#2 and so on<br />
may anybody help me?<br />
thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joy</title>
		<link>http://inchoo.net/wordpress/hierarchy-identification-child-parent-page/comment-page-1/#comment-254</link>
		<dc:creator>Joy</dc:creator>
		<pubDate>Thu, 23 Oct 2008 00:45:59 +0000</pubDate>
		<guid isPermaLink="false">http://inchoo.net/?p=156#comment-254</guid>
		<description>This looks useful for complicated hierarchies. (Does anyone do that?)
I have a couple of problems with the code though.

First, always use a single return! especially with a recursive function.

Second, if you pass in an array you&#039;re asking the question &quot;Is the current page in any of these hierarchies?&quot;, so you can fully return as soon as you find a yes answer. To do that, put a break in the if of the foreach.

Third, the &#039;and&#039; and &#039;or&#039; operators have lower precedence, so your if statement is a little funky. This functions should only be checking actual pages, not posts, so the check for $post-&gt;post_type==&#039;page&#039; should be before anything else is done, around line 2. Because the &#039;==&#039; is highest precedence of the expression, it gets evaluated first, then the isset and the in_array, then the &#039;&amp;&amp;&#039; of the two, then the &#039;and&#039; with the first part. If none of it was true, it will finally check if the page_id is a page. This leads me to question why you have this check returning true like that...if the current post is not a page, but the id you are checking  is, you will wrongly return a true value.

I&#039;m putting a modified version here, please pardon me in advance if it doesn&#039;t come through correctly from this comment form. I didn&#039;t test the changes I made.
&lt;code&gt;
function in_page_hierarchy_for($page_id) {
  global $post;
  $r = false;
  if ($post-&gt;post_type == &#039;page&#039; &amp;&amp; isset($post-&gt;ancestors)) { 
    if (is_array($page_id)) {
      foreach ($page_id as $pid) 
        if (in_page_hierarchy_for($pid) == true) {
          $r = true;
          break;
          }
      } 
    else {
      if (is_page($page_id) &amp;&amp; in_array($page_id, $post-&gt;ancestors))
        $r = true;
      }
    }
  return $r;
  }
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>This looks useful for complicated hierarchies. (Does anyone do that?)<br />
I have a couple of problems with the code though.</p>
<p>First, always use a single return! especially with a recursive function.</p>
<p>Second, if you pass in an array you&#8217;re asking the question &#8220;Is the current page in any of these hierarchies?&#8221;, so you can fully return as soon as you find a yes answer. To do that, put a break in the if of the foreach.</p>
<p>Third, the &#8216;and&#8217; and &#8216;or&#8217; operators have lower precedence, so your if statement is a little funky. This functions should only be checking actual pages, not posts, so the check for $post-&gt;post_type==&#8217;page&#8217; should be before anything else is done, around line 2. Because the &#8216;==&#8217; is highest precedence of the expression, it gets evaluated first, then the isset and the in_array, then the &#8216;&amp;&amp;&#8217; of the two, then the &#8216;and&#8217; with the first part. If none of it was true, it will finally check if the page_id is a page. This leads me to question why you have this check returning true like that&#8230;if the current post is not a page, but the id you are checking  is, you will wrongly return a true value.</p>
<p>I&#8217;m putting a modified version here, please pardon me in advance if it doesn&#8217;t come through correctly from this comment form. I didn&#8217;t test the changes I made.<br />
<code><br />
function in_page_hierarchy_for($page_id) {<br />
  global $post;<br />
  $r = false;<br />
  if ($post-&gt;post_type == 'page' &amp;&amp; isset($post-&gt;ancestors)) {<br />
    if (is_array($page_id)) {<br />
      foreach ($page_id as $pid)<br />
        if (in_page_hierarchy_for($pid) == true) {<br />
          $r = true;<br />
          break;<br />
          }<br />
      }<br />
    else {<br />
      if (is_page($page_id) &amp;&amp; in_array($page_id, $post-&gt;ancestors))<br />
        $r = true;<br />
      }<br />
    }<br />
  return $r;<br />
  }<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darin</title>
		<link>http://inchoo.net/wordpress/hierarchy-identification-child-parent-page/comment-page-1/#comment-212</link>
		<dc:creator>Darin</dc:creator>
		<pubDate>Mon, 06 Oct 2008 23:01:32 +0000</pubDate>
		<guid isPermaLink="false">http://inchoo.net/?p=156#comment-212</guid>
		<description>Perfect!  This is exactly what I needed today.  Thank you so much, saved me some time hacking my own php.

By the way, on line 15, the html entities for the ampersands need to be replaced with the actual things.</description>
		<content:encoded><![CDATA[<p>Perfect!  This is exactly what I needed today.  Thank you so much, saved me some time hacking my own php.</p>
<p>By the way, on line 15, the html entities for the ampersands need to be replaced with the actual things.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

