Skip to content

Instantly share code, notes, and snippets.

@stephanieleary
Last active October 3, 2015 19:48
Show Gist options
  • Save stephanieleary/2515667 to your computer and use it in GitHub Desktop.
Save stephanieleary/2515667 to your computer and use it in GitHub Desktop.
List Child Pages
<?php
/*
Plugin Name: Steph's Tiny List Child Pages Plugin
Plugin URI: http://sillybean.net/2010/06/listing-child-pages-with-a-shortcode/
Description: Lets you list child pages using a shortcode. Also displays child page list by default on empty parent pages.
Author: Stephanie Leary
Version: 1.0
Author URI: http://sillybean.net/
License: GPL v2 or later
*/
// note depth = 0 (no hierarchy)
function scl_child_pages_shortcode() {
$id = get_the_ID();
return '<ul class="childpages">'.wp_list_pages( 'echo=0&depth=0&title_li=&child_of='.$id ).'</ul>';
}
add_shortcode( 'child-pages', 'scl_child_pages_shortcode' );
add_shortcode( 'children', 'scl_child_pages_shortcode' );
add_shortcode( 'subpages', 'scl_child_pages_shortcode' );
// note no depth argument (full hierarchy)
function scl_append_child_pages( $content ) {
$children = '';
if ( is_page() && ( empty($content) ) ) {
$id = get_the_ID();
$children = '<ul class="childpages">'.wp_list_pages( 'echo=0&title_li=&child_of='.$id ).'</ul>';
}
return $content.$children;
}
add_filter( 'the_content', 'scl_append_child_pages' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment