Forums

List subpages of a page with an array (2 posts)

  1. hairness
    Member
    Posted 3 years ago #

    hello

    im getting all subpages of a page which looks kinda lika this

    f($post->post_parent)
    $children = wp_list_pages("title_li=&depth=1&child_of=".$post->ID."&echo=0");
    if ($children) {
    echo $children;
    }

    there are 2 subpages, which are also correctly displayed, but somehow afterwards, not like in an array
    i need a way to excute code for every subpage like this

    while (there are any subpages) {
    do this and that
    }

    can someone give me a hint how to solve this

    tanks

  2. Michael Fields
    Theme Wrangler
    Posted 3 years ago #

    This is how I do it:

    $pageChildren = $wpdb->get_results("
    	SELECT *
    	FROM $wpdb->posts
    	WHERE post_parent = ".$post->ID."
    	AND post_type = 'page'
    	ORDER BY menu_order	", 'OBJECT');
    
    if ( $pageChildren ) :
    	foreach ( $pageChildren as $pageChild ) :
    
    		setup_postdata( $pageChild );
    
    		/* Template Tags go here!!!! */
    
    	endforeach;
    endif; ?>

    Hope this helps

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.