<?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: WordPress: is_child function</title>
	<atom:link href="http://www.christianschenk.org/blog/wordpress-is_child-function/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christianschenk.org/blog/wordpress-is_child-function/</link>
	<description>Writing about my experiences with technology and all different kinds of projects and experiments</description>
	<lastBuildDate>Mon, 30 Jan 2012 19:10:22 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: Jemma</title>
		<link>http://www.christianschenk.org/blog/wordpress-is_child-function/comment-page-1/#comment-36399</link>
		<dc:creator>Jemma</dc:creator>
		<pubDate>Tue, 16 Aug 2011 20:02:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/?p=735#comment-36399</guid>
		<description>Thank you, that&#039;s fixed it, I was just using page names, instead of slugs, which works for is_page, but not is_child.  What a useful plugin, thanks very much!</description>
		<content:encoded><![CDATA[<p>Thank you, that&#8217;s fixed it, I was just using page names, instead of slugs, which works for is_page, but not is_child.  What a useful plugin, thanks very much!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Schenk</title>
		<link>http://www.christianschenk.org/blog/wordpress-is_child-function/comment-page-1/#comment-36362</link>
		<dc:creator>Christian Schenk</dc:creator>
		<pubDate>Mon, 15 Aug 2011 21:37:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/?p=735#comment-36362</guid>
		<description>Hi Jemma,
you&#039;ll have to supply the slug or the ID of the post in the &lt;code&gt;is_child&lt;/code&gt; function. Have you tried the slug, i.e. something like &lt;em&gt;sabah-borneosabah-borneo&lt;/em&gt;, or the post&#039;s ID instead yet?</description>
		<content:encoded><![CDATA[<p>Hi Jemma,<br />
you&#8217;ll have to supply the slug or the ID of the post in the <code>is_child</code> function. Have you tried the slug, i.e. something like <em>sabah-borneosabah-borneo</em>, or the post&#8217;s ID instead yet?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jemma</title>
		<link>http://www.christianschenk.org/blog/wordpress-is_child-function/comment-page-1/#comment-36154</link>
		<dc:creator>Jemma</dc:creator>
		<pubDate>Wed, 10 Aug 2011 20:45:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/?p=735#comment-36154</guid>
		<description>Hi Christian,

This looks just like what I need for my site, but it doesn&#039;t seem to be working for me.

I have the following code in my header.php:
&lt;code&gt;
&lt;?php if ( (is_page(&#039;&lt;!--:en--&gt;Sabah, Borneo&lt;!--:--&gt;&lt;!--:ms--&gt;Sabah, Borneo&lt;!--:--&gt;&#039;)) &#124;&#124; (is_child(&#039;&lt;!--:en--&gt;Sabah, Borneo&lt;!--:--&gt;&lt;!--:ms--&gt;Sabah, Borneo&lt;!--:--&gt;&#039;)) ): ?&gt;
&lt;/code&gt;

I know it&#039;s not very pretty, but I&#039;m new to all this.  The problem is the menu displays on the parent page but not the children page.

When I use &#039;array&#039; within &#039;is_page&#039; and list all the page names manually it works, but obviously that is not the best solution to my problem.

Could you point me in the right direction to fix my problem please?

Thanks,
Jemma</description>
		<content:encoded><![CDATA[<p>Hi Christian,</p>
<p>This looks just like what I need for my site, but it doesn&#8217;t seem to be working for me.</p>
<p>I have the following code in my header.php:<br />
<code><br />
&lt;?php if ( (is_page(&#039;<!--:en-->Sabah, Borneo<!--:--><!--:ms-->Sabah, Borneo<!--:-->')) || (is_child('<!--:en-->Sabah, Borneo<!--:--><!--:ms-->Sabah, Borneo<!--:-->')) ): ?&gt;<br />
</code></p>
<p>I know it&#8217;s not very pretty, but I&#8217;m new to all this.  The problem is the menu displays on the parent page but not the children page.</p>
<p>When I use &#8216;array&#8217; within &#8216;is_page&#8217; and list all the page names manually it works, but obviously that is not the best solution to my problem.</p>
<p>Could you point me in the right direction to fix my problem please?</p>
<p>Thanks,<br />
Jemma</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Schenk</title>
		<link>http://www.christianschenk.org/blog/wordpress-is_child-function/comment-page-1/#comment-33368</link>
		<dc:creator>Christian Schenk</dc:creator>
		<pubDate>Thu, 09 Jun 2011 23:52:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/?p=735#comment-33368</guid>
		<description>Hi Jeff,
basically the plugin was pretty easy to write, partly due to the straight forward database schema of WordPress which made it easy grabbing the needed information. In fact, the codex &lt;a href=&quot;http://codex.wordpress.org/Conditional_Tags#Testing_for_sub-Pages&quot; rel=&quot;nofollow&quot;&gt;mentions&lt;/a&gt; similar ways solving this kind of issue. Since I wanted a solution that could not only handle post IDs but slugs as well and would work for more than one hierarchy - a is a parent of b, b is a parent of c and &lt;code&gt;is_child(&#039;a&#039;)&lt;/code&gt; returns &lt;code&gt;true&lt;/code&gt; on page c as well - I created this plugin. Short answer, WordPress has (limited) support for this - if you want a nice, clean solution simply use this plugin ;-)</description>
		<content:encoded><![CDATA[<p>Hi Jeff,<br />
basically the plugin was pretty easy to write, partly due to the straight forward database schema of WordPress which made it easy grabbing the needed information. In fact, the codex <a href="http://codex.wordpress.org/Conditional_Tags#Testing_for_sub-Pages" rel="nofollow">mentions</a> similar ways solving this kind of issue. Since I wanted a solution that could not only handle post IDs but slugs as well and would work for more than one hierarchy &#8211; a is a parent of b, b is a parent of c and <code>is_child('a')</code> returns <code>true</code> on page c as well &#8211; I created this plugin. Short answer, WordPress has (limited) support for this &#8211; if you want a nice, clean solution simply use this plugin <img src='http://www.christianschenk.org/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Kinley</title>
		<link>http://www.christianschenk.org/blog/wordpress-is_child-function/comment-page-1/#comment-33361</link>
		<dc:creator>Jeff Kinley</dc:creator>
		<pubDate>Thu, 09 Jun 2011 18:10:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/?p=735#comment-33361</guid>
		<description>Hi,

Thanks for the help, I was looking all over for this and your is_child plugin saved me a lot of work. I&#039;m pretty new to PHP and always looking for any help I can get. I was surprised how hard it was to tell Wordpress to show content on the About and page and all the About page&#039;s children. Why is it so hard? Why did you have to write so much code in is_child to make that work.

Here is the function I added to my custom-functions.php:

&lt;pre lang=&quot;php&quot;&gt;
function about_menu() {
  if (( is_page(&#039;about&#039;)) &#124;&#124; (is_child(&#039;about&#039;))){
    wp_nav_menu( array( &#039;container_class&#039; =&gt; &#039;about-menu&#039;,
                        &#039;theme_location&#039; =&gt; &#039;about&#039; ) );
  }
}
add_action(&#039;thesis_hook_after_header&#039;,&#039;about_menu&#039;);
&lt;/pre&gt;

This of course makes sense to me, but without your is_child in there, is there anyway else you could do it in Wordpress? Seems silly that this is not built into their list of conditionals.

Thanks again,
JK</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Thanks for the help, I was looking all over for this and your is_child plugin saved me a lot of work. I&#8217;m pretty new to PHP and always looking for any help I can get. I was surprised how hard it was to tell WordPress to show content on the About and page and all the About page&#8217;s children. Why is it so hard? Why did you have to write so much code in is_child to make that work.</p>
<p>Here is the function I added to my custom-functions.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> about_menu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span> is_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'about'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>is_child<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'about'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    wp_nav_menu<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'container_class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'about-menu'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'theme_location'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'about'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thesis_hook_after_header'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'about_menu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This of course makes sense to me, but without your is_child in there, is there anyway else you could do it in WordPress? Seems silly that this is not built into their list of conditionals.</p>
<p>Thanks again,<br />
JK</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Wiersema</title>
		<link>http://www.christianschenk.org/blog/wordpress-is_child-function/comment-page-1/#comment-24765</link>
		<dc:creator>Dan Wiersema</dc:creator>
		<pubDate>Thu, 03 Feb 2011 19:56:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/?p=735#comment-24765</guid>
		<description>Works perfect man, thanks!! This really should be built in to WordPress.</description>
		<content:encoded><![CDATA[<p>Works perfect man, thanks!! This really should be built in to WordPress.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yann Bouschet</title>
		<link>http://www.christianschenk.org/blog/wordpress-is_child-function/comment-page-1/#comment-21176</link>
		<dc:creator>Yann Bouschet</dc:creator>
		<pubDate>Mon, 22 Nov 2010 18:43:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/?p=735#comment-21176</guid>
		<description>Just what I needed.
Simple and elegant, works perfectly : Thank you !</description>
		<content:encoded><![CDATA[<p>Just what I needed.<br />
Simple and elegant, works perfectly : Thank you !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Schenk</title>
		<link>http://www.christianschenk.org/blog/wordpress-is_child-function/comment-page-1/#comment-15089</link>
		<dc:creator>Christian Schenk</dc:creator>
		<pubDate>Sun, 18 Apr 2010 10:19:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/?p=735#comment-15089</guid>
		<description>Hi Chris,
this post was meant for programmers with a basic understanding of PHP and WordPress in general. I&#039;m sorry that this post isn&#039;t that clear for you but here&#039;s how to use the plugin:
&lt;ol&gt;
&lt;li&gt;install and activate the plugin. Note that this won&#039;t change your theme&#039;s &lt;code&gt;functions.php&lt;/code&gt; in any way.&lt;/li&gt;
&lt;li&gt;use the function &lt;code&gt;is_child&lt;/code&gt; where ever you want to make sure that the current post/page is a descendant of the given parent post/page.&lt;/li&gt;
&lt;/ol&gt;
Say, you&#039;ve got a page with the ID 4711 and another page with the ID 4712 where the latter is a child page of the first one. The function call &lt;code&gt;is_child(4711)&lt;/code&gt; will evaluate to true if you&#039;re requesting any of this page&#039;s sub pages, e.g. the one with the ID 4712.</description>
		<content:encoded><![CDATA[<p>Hi Chris,<br />
this post was meant for programmers with a basic understanding of PHP and WordPress in general. I&#8217;m sorry that this post isn&#8217;t that clear for you but here&#8217;s how to use the plugin:</p>
<ol>
<li>install and activate the plugin. Note that this won&#8217;t change your theme&#8217;s <code>functions.php</code> in any way.</li>
<li>use the function <code>is_child</code> where ever you want to make sure that the current post/page is a descendant of the given parent post/page.</li>
</ol>
<p>Say, you&#8217;ve got a page with the ID 4711 and another page with the ID 4712 where the latter is a child page of the first one. The function call <code>is_child(4711)</code> will evaluate to true if you&#8217;re requesting any of this page&#8217;s sub pages, e.g. the one with the ID 4712.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://www.christianschenk.org/blog/wordpress-is_child-function/comment-page-1/#comment-15066</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Fri, 16 Apr 2010 20:50:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.christianschenk.org/?p=735#comment-15066</guid>
		<description>How about a little help with this plug-in....
Can you spell it out. Step 123...

Do I need to add this...  

function is_child($parent) {
  global $post;
  return $post-&gt;post_parent == $parent;
}

to my functions.php or not? I&#039;ve seen it implemented around the web &quot;Most of the time it’s something like the following:&quot; not clear!

can you give an example of how to call this function would it be added to the (list item) of the subpage or to the (list item) that holds the subpages? not clear

Installing this plug-in didn&#039;t seem to change my themes functions.php was it supost to? help!</description>
		<content:encoded><![CDATA[<p>How about a little help with this plug-in&#8230;.<br />
Can you spell it out. Step 123&#8230;</p>
<p>Do I need to add this&#8230;  </p>
<p>function is_child($parent) {<br />
  global $post;<br />
  return $post-&gt;post_parent == $parent;<br />
}</p>
<p>to my functions.php or not? I&#8217;ve seen it implemented around the web &#8220;Most of the time it’s something like the following:&#8221; not clear!</p>
<p>can you give an example of how to call this function would it be added to the (list item) of the subpage or to the (list item) that holds the subpages? not clear</p>
<p>Installing this plug-in didn&#8217;t seem to change my themes functions.php was it supost to? help!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

