<?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>Inchoo - E-Commerce &#38; Magento discussion</description>
	<pubDate>Tue, 06 Jan 2009 02:48:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<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're asking the question "Is the current page in any of these hierarchies?", 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 'and' and 'or' 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-&#62;post_type=='page' should be before anything else is done, around line 2. Because the '==' is highest precedence of the expression, it gets evaluated first, then the isset and the in_array, then the '&#38;&#38;' of the two, then the 'and' 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'm putting a modified version here, please pardon me in advance if it doesn't come through correctly from this comment form. I didn't test the changes I made.
&lt;code&gt;
function in_page_hierarchy_for($page_id) {
  global $post;
  $r = false;
  if ($post-&#62;post_type == 'page' &#38;&#38; isset($post-&#62;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) &#38;&#38; in_array($page_id, $post-&#62;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>
