Welcome, guest!

Feel free to read the blog, browse for themes, or join the club.

Can't List Sub Pages Via add_action

  1. 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.

  2. You must be a logged-in exclusive member to view this reply.

  3. That did it. Thanks!

Reply

You must log in to post.

Limited Access

If you have an account, please take a moment to log in.

Non-exclusive members have limited access to the support forums.

To enjoy the full range of support, sign up for an exclusive membership in the theme club.

Support Forums

  • Bliss Theme (253 posts)
  • Hybrid Theme (21,735 posts)
  • Options Theme (10,356 posts)
  • Structure Theme (2,747 posts)
  • Outline Theme (36 posts)
  • Visionary Theme (767 posts)
  • bbPress Themes (305 posts)
  • WordPress Plugins (2,045 posts)
  • General Discussion (5,276 posts)