Sillybean

Listing children on empty pages as a filter

Yesterday, I showed you how to automatically list child pages if a page’s content is empty. That code would go in your theme’s page.php file. What if you wanted to use it in any theme? The best solution is to turn it into a little plugin:

/*
Plugin Name: List Children on Empty Pages
Plugin Author: Stephanie Leary
*/

function append_child_pages($content) {
   $children = '';
   if (is_page() && (empty($content))) {
      global $post;
      $children = '
<ul class="childpages">'.wp_list_pages('echo=0&title_li=&child_of='.$post->ID).'</ul>
';
   }
   return $content.$children;
}
add_filter('the_content','append_child_pages');
?>

Paste the code into a file in your wp-content/plugins directory (something like append-child-pages.php), activate it, and it’ll work no matter which theme you choose.

Posted on June 3, 2010 at 8:57 pm in WordPress · comment

Sharing this post? The short URL is: http://sillybean.net/?p=5246

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>