I love the Piano Black WordPress theme but it hasn’t been updated in a while and doesn’t support WordPress’ native menus. This isn’t a big enough drawback for me to change to a different theme and with a few tweaks here and there I’m satisfied with the current state of the menus. Other than the several blog posts, I’ve also created a hierarchy of pages for both my project pages and code samples.
What I didn’t want to have to do is to update each category landing page whenever adding child pages to it so I created a few template pages, this one is simply called ‘List child page titles’. Dropping this into a file within your WordPress theme directory and making sure that ‘Template Name’ comment is still in place will give an additional drop-down option for ‘Template’ in the ‘Edit Page’ screen for the page/post you’re editing.
Show the code
<?php
/*
Template Name:List child page titles
*/
?>
<?php get_header(); ?>
<div id="middle-contents" class="clearfix">
<div id="left-col">
<?php the_ID(); $parent = $post->ID; ?>
<div class="common-navi-wrapper">
<p><?php the_title();?></p>
</div>
<div class="post" id="single">
<div class="post-content">
<?php the_post(); if (the_content()) :;?>
<ul class="post-info"><?php the_content();?></ul>
<?php endif; ?>
<?php
// use wp_list_pages to display parent and all child pages all generations (a tree with parent)
$args=array(
'child_of' => $parent
);
$pages = get_pages($args);
if ($pages) {
$pageids = array();
foreach ($pages as $page) {
$pageids[]= $page->ID;
}
$args=array(
'title_li' => '',
'include' => implode(",", $pageids)
);
wp_list_pages($args);
}
?>
</div>
</div>
</div><!-- #left-col end -->
<?php get_sidebar(); ?>
</div><!-- #middle-contents end -->
<?php get_footer(); ?>