rendered paste body<?php
// if this is a top-level page, check for child pages
$parent_title = get_the_title($post->post_parent);
if($parent_title == get_the_title()) {
$parent_id = $post->ID; //top level page
}
else {
$parent_id = $post->post_parent;
}
$today = current_time('mysql', 1);
$query_related = "SELECT ID, post_title, post_name, menu_order FROM $wpdb->posts";
$query_related .= " WHERE post_status = 'publish' AND post_date_gmt < '$today' AND post_type = 'page' AND post_parent = ";
$query_related .= $parent_id;
$query_related .= " ORDER BY 'menu_order' ASC";
if ( $relatedpages = $wpdb->get_results($query_related)){
?>
<h5><?php _e($parent_title); ?></h5>
<ul id="children">
<?php
foreach ($relatedpages as $post) {
if ($post->post_title == '')
$post->post_title = sprintf(__('Post #%s'), $post->ID);
echo "<li><a href='".get_permalink($post->ID)."'>";
the_title();
echo '</a></li>';
}
?>
</ul>
<?php
} //children or siblings exist
?>