<?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: Get Depth &#8211; like is_child() &amp; is_grandchild()</title>
	<atom:link href="http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 20 Aug 2010 07:17:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ola</title>
		<link>http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/comment-page-1/#comment-6066</link>
		<dc:creator>Ola</dc:creator>
		<pubDate>Fri, 26 Feb 2010 21:09:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.web-templates.nu/?p=37#comment-6066</guid>
		<description>Wow, this really helped me out a lot..thanks!!!  :D</description>
		<content:encoded><![CDATA[<p>Wow, this really helped me out a lot..thanks!!!  <img src='http://www.web-templates.nu/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tristan</title>
		<link>http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/comment-page-1/#comment-5882</link>
		<dc:creator>Tristan</dc:creator>
		<pubDate>Fri, 29 Jan 2010 05:31:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.web-templates.nu/?p=37#comment-5882</guid>
		<description>To return just the level below the current page you need this:
get_pages(&#039;child_of=&#039;.$post-&gt;ID.&#039;&amp;parent=&#039;.$post-&gt;ID);
foreach ($pages as $page) {

//something in here

}

Hope this helps :)</description>
		<content:encoded><![CDATA[<p>To return just the level below the current page you need this:<br />
get_pages(&#8216;child_of=&#8217;.$post-&gt;ID.&#8217;&amp;parent=&#8217;.$post-&gt;ID);<br />
foreach ($pages as $page) {</p>
<p>//something in here</p>
<p>}</p>
<p>Hope this helps <img src='http://www.web-templates.nu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chrille</title>
		<link>http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/comment-page-1/#comment-5798</link>
		<dc:creator>Chrille</dc:creator>
		<pubDate>Tue, 19 Jan 2010 13:43:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.web-templates.nu/?p=37#comment-5798</guid>
		<description>Hi!

If you would like too get a different echo for each parent/grandparent? How would you do that and where should i put the code?

My page is : http://trollback.se/urskog/products/lov/walnut/

So I want headerMeny to be highlighted and &quot;lov&quot; when on a subpage to them. So how should i code this?
This is a extract from my current meny:

&lt;li class=&quot;mainNav_Lov&quot;&gt;
					&lt;a href=&quot;/products/lov/walnut&quot;&gt;&lt;/a&gt;
				

THIS IS MY HEADER MENY:

                       &lt;li class=&quot;products&quot;&gt;
                &lt;a href=&quot;/products/lov/walnut&quot;&gt;&lt;/a&gt;
        	

Basicly I want to get &quot;LÖV&quot; highlighed with :  id = current2 
and I want Products to be hlighlighted  : id= current

Thank you!</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>If you would like too get a different echo for each parent/grandparent? How would you do that and where should i put the code?</p>
<p>My page is : <a href="http://trollback.se/urskog/products/lov/walnut/" rel="nofollow">http://trollback.se/urskog/products/lov/walnut/</a></p>
<p>So I want headerMeny to be highlighted and &#8220;lov&#8221; when on a subpage to them. So how should i code this?<br />
This is a extract from my current meny:</p>
<p>&lt;li class=&quot;mainNav_Lov&quot;&gt;<br />
					&lt;a href=&quot;/products/lov/walnut&#8221;&gt;</p>
<p>THIS IS MY HEADER MENY:</p>
<p>                       &lt;li class=&quot;products&quot;&gt;<br />
                &lt;a href=&quot;/products/lov/walnut&#8221;&gt;</p>
<p>Basicly I want to get &#8220;LÖV&#8221; highlighed with :  id = current2<br />
and I want Products to be hlighlighted  : id= current</p>
<p>Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joseph</title>
		<link>http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/comment-page-1/#comment-3256</link>
		<dc:creator>Joseph</dc:creator>
		<pubDate>Thu, 09 Jul 2009 16:31:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.web-templates.nu/?p=37#comment-3256</guid>
		<description>Thanks for the function! Saved me a headache.</description>
		<content:encoded><![CDATA[<p>Thanks for the function! Saved me a headache.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vybes</title>
		<link>http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/comment-page-1/#comment-3164</link>
		<dc:creator>vybes</dc:creator>
		<pubDate>Mon, 29 Jun 2009 19:14:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.web-templates.nu/?p=37#comment-3164</guid>
		<description>hey, thank you for the code. i was looking for a code to check the depth of a category, i tweaked your code and it helped solve a problem i was trying to solve.big up.

here is the code to get the depth of categories;

function wt_get_depth($id = &#039;&#039;, $depth = &#039;&#039;, $i = 0)
{
	global $wpdb;
	global $term_taxonomy;

	if($depth == &#039;&#039;)
	{
		if(is_category())
		{
			if($id == &#039;&#039;)
			{
				$id = $term_taxonomy-&gt;term_id;
			}
			$depth = $wpdb-&gt;get_var(&quot;SELECT parent FROM $wpdb-&gt;term_taxonomy WHERE term_id = &#039;&quot;.$id.&quot;&#039;&quot;);
			return wt_get_depth($id, $depth, $i);
		}
	}
	elseif($depth == &quot;0&quot;)
	{
		return $i;
	}
	else
	{
		$depth = $wpdb-&gt;get_var(&quot;SELECT parent FROM $wpdb-&gt;term_taxonomy WHERE term_id = &#039;&quot;.$depth.&quot;&#039;&quot;);
		$i++;
		return wt_get_depth($id, $depth, $i);
	}
}</description>
		<content:encoded><![CDATA[<p>hey, thank you for the code. i was looking for a code to check the depth of a category, i tweaked your code and it helped solve a problem i was trying to solve.big up.</p>
<p>here is the code to get the depth of categories;</p>
<p>function wt_get_depth($id = &#8221;, $depth = &#8221;, $i = 0)<br />
{<br />
	global $wpdb;<br />
	global $term_taxonomy;</p>
<p>	if($depth == &#8221;)<br />
	{<br />
		if(is_category())<br />
		{<br />
			if($id == &#8221;)<br />
			{<br />
				$id = $term_taxonomy-&gt;term_id;<br />
			}<br />
			$depth = $wpdb-&gt;get_var(&#8220;SELECT parent FROM $wpdb-&gt;term_taxonomy WHERE term_id = &#8216;&#8221;.$id.&#8221;&#8216;&#8221;);<br />
			return wt_get_depth($id, $depth, $i);<br />
		}<br />
	}<br />
	elseif($depth == &#8220;0&#8243;)<br />
	{<br />
		return $i;<br />
	}<br />
	else<br />
	{<br />
		$depth = $wpdb-&gt;get_var(&#8220;SELECT parent FROM $wpdb-&gt;term_taxonomy WHERE term_id = &#8216;&#8221;.$depth.&#8221;&#8216;&#8221;);<br />
		$i++;<br />
		return wt_get_depth($id, $depth, $i);<br />
	}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marty Thornley</title>
		<link>http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/comment-page-1/#comment-3073</link>
		<dc:creator>Marty Thornley</dc:creator>
		<pubDate>Mon, 15 Jun 2009 21:34:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.web-templates.nu/?p=37#comment-3073</guid>
		<description>Copied the wrong code... Oops.

the line finding the parent of the post should be:

if ($post-&gt;post_parent) $parent = $post-&gt;post_parent;

not:

if ($post-&gt;post_parent) $parent = get_page($post-&gt;post_parent);</description>
		<content:encoded><![CDATA[<p>Copied the wrong code&#8230; Oops.</p>
<p>the line finding the parent of the post should be:</p>
<p>if ($post-&gt;post_parent) $parent = $post-&gt;post_parent;</p>
<p>not:</p>
<p>if ($post-&gt;post_parent) $parent = get_page($post-&gt;post_parent);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marty Thornley</title>
		<link>http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/comment-page-1/#comment-3072</link>
		<dc:creator>Marty Thornley</dc:creator>
		<pubDate>Mon, 15 Jun 2009 21:29:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.web-templates.nu/?p=37#comment-3072</guid>
		<description>I had been searching for an answer to the &#039;is_grandchild_of(idhere)&#039; idea myself.

This is what I came up with as a modification of the is_tree() idea mentioned in the codex but only checks a specific number of levels. My next step would be to combine it with your get_depth idea:

function is_tree($pid) {   
	global $post;       	
	if ($post-&gt;post_parent) $parent = get_page($post-&gt;post_parent);
	if ($parent-&gt;post_parent) $grand = get_page($parent-&gt;post_parent);
	if ($grand-&gt;post_parent) $great = get_page($grand-&gt;post_parent);
	if ($great-&gt;post_parent) $gr8gr8 = get_page($great-&gt;post_parent);
	if (is_page($pid) &#124;&#124; $parent==$pid &#124;&#124; $grand-&gt;ID==$pid &#124;&#124; $great-&gt;ID==$pid &#124;&#124; $gr8gr8-&gt;ID==$pid) :
        return true; // Yes, it&#039;s in the tree
	else : return false;  	// No, it&#039;s outside
	endif;</description>
		<content:encoded><![CDATA[<p>I had been searching for an answer to the &#8216;is_grandchild_of(idhere)&#8217; idea myself.</p>
<p>This is what I came up with as a modification of the is_tree() idea mentioned in the codex but only checks a specific number of levels. My next step would be to combine it with your get_depth idea:</p>
<p>function is_tree($pid) {<br />
	global $post;<br />
	if ($post-&gt;post_parent) $parent = get_page($post-&gt;post_parent);<br />
	if ($parent-&gt;post_parent) $grand = get_page($parent-&gt;post_parent);<br />
	if ($grand-&gt;post_parent) $great = get_page($grand-&gt;post_parent);<br />
	if ($great-&gt;post_parent) $gr8gr8 = get_page($great-&gt;post_parent);<br />
	if (is_page($pid) || $parent==$pid || $grand-&gt;ID==$pid || $great-&gt;ID==$pid || $gr8gr8-&gt;ID==$pid) :<br />
        return true; // Yes, it&#8217;s in the tree<br />
	else : return false;  	// No, it&#8217;s outside<br />
	endif;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl</title>
		<link>http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/comment-page-1/#comment-2625</link>
		<dc:creator>Karl</dc:creator>
		<pubDate>Thu, 09 Apr 2009 06:40:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.web-templates.nu/?p=37#comment-2625</guid>
		<description>Hi there,

Perhaps this is similar to Jonathan&#039;s query, but I&#039;m almost losing track of what I&#039;m looking for after having visited so many pages!

On a page, I&#039;m trying to loop out the grand children of the page I&#039;m at, grouping them by child - is that possible with this code? I&#039;ve got a template for a specific page, where I&#039;d like to get the title of each child and underneath each child list page data from the grandchildren. Something like

CHILD 1 TITLE
- Grandchild 1 with title and description
- Grandchild 2 with title and description

CHILD 2 TITLE
- Grandchild 1 with title and description
- Grandchild 2 with title and description

Any pointers on this would be great, ideally a code example to help a feeble mind!</description>
		<content:encoded><![CDATA[<p>Hi there,</p>
<p>Perhaps this is similar to Jonathan&#8217;s query, but I&#8217;m almost losing track of what I&#8217;m looking for after having visited so many pages!</p>
<p>On a page, I&#8217;m trying to loop out the grand children of the page I&#8217;m at, grouping them by child &#8211; is that possible with this code? I&#8217;ve got a template for a specific page, where I&#8217;d like to get the title of each child and underneath each child list page data from the grandchildren. Something like</p>
<p>CHILD 1 TITLE<br />
- Grandchild 1 with title and description<br />
- Grandchild 2 with title and description</p>
<p>CHILD 2 TITLE<br />
- Grandchild 1 with title and description<br />
- Grandchild 2 with title and description</p>
<p>Any pointers on this would be great, ideally a code example to help a feeble mind!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jonathan</title>
		<link>http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/comment-page-1/#comment-2610</link>
		<dc:creator>jonathan</dc:creator>
		<pubDate>Tue, 07 Apr 2009 16:31:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.web-templates.nu/?p=37#comment-2610</guid>
		<description>hi

very useful code. however, i&#039;d like to have something like

is_grand_child_of(page_id_here) 

....

is it possible with this code ?

thanks</description>
		<content:encoded><![CDATA[<p>hi</p>
<p>very useful code. however, i&#8217;d like to have something like</p>
<p>is_grand_child_of(page_id_here) </p>
<p>&#8230;.</p>
<p>is it possible with this code ?</p>
<p>thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yoni</title>
		<link>http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/comment-page-1/#comment-1669</link>
		<dc:creator>yoni</dc:creator>
		<pubDate>Wed, 25 Feb 2009 21:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.web-templates.nu/?p=37#comment-1669</guid>
		<description>hey can you conceive of a get_depth for CATEGORIES (ie i want to use get_categories but only display one depth, not all the subchildren)?  i know wp_list_categories does this, but it echoes a list, not generate an array like get_categories...
thanks!</description>
		<content:encoded><![CDATA[<p>hey can you conceive of a get_depth for CATEGORIES (ie i want to use get_categories but only display one depth, not all the subchildren)?  i know wp_list_categories does this, but it echoes a list, not generate an array like get_categories&#8230;<br />
thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
