So I'm trying to list a page's sub pages or other same-level pages. My function to do so is below and it works when I put it directly into a template, but not when I use the add_action method. So here's what I have:
add_action( 'hybrid_after_primary', 'marathon_child_pages', 11 );
function marathon_child_pages() {
if( $post->post_parent ) {
$children = wp_list_pages("post_type=page&title_li=&child_of=".$post->post_parent."&echo=0");
$titlenamer = get_the_title($post->post_parent);
} else {
$children = wp_list_pages("post_type=page&title_li=&child_of=".$post->post_parent."&echo=0");
$titlenamer = get_the_title($post->post_parent);
}
if ($children) {
echo '<h2>'. $titlenamer .'</h2>';
echo '<ul>';
echo $children;
echo '</ul>';
}
}
I must need to call something else, and I tried global $wp_query but that didn't help.
By it "not working" I mean that instead of rendering the pages that should be output it is listing all pages.