WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] The Loop and subpages (6 posts)

  1. henkblanken
    Member
    Posted 8 years ago #

    I want to use The Loop to get not a certain page (you can do that with is_page() ) but a couple of childpages. This is the code, and it's not working:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if ( is_page('child_of=7') ) : ?>
    <?php the_title(); ?>
    <?php the_excerpt(); ?>
    <?php else: ?>
    Sorry
    <?php
    endif; ?>

    <?php endwhile; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>

    (PS: 7 is the id of the parent page)

    Is this not supposed to work? Should I do something less stupid? Thnx

  2. Joshua Sigar
    Member
    Posted 8 years ago #

    Nope, that's not gonna work. Dunno, something like this.

    <?php
    $my_pages = &get_pages('child_of=7');
    foreach ($my_pages as $page)
    {
    setup_postdata($page);
    the_title();
    the_excerpt();
    }
    ?>

  3. henkblanken
    Member
    Posted 8 years ago #

    Thnx, but no, that doesnt work. It returns as many titles as there are childs. So it's almost working. I'll have another look.

  4. Joshua Sigar
    Member
    Posted 8 years ago #

    It returns as many titles as there are childs.
    Well, it is supposed to.

    You may need to rephrase either your observation or your request.

  5. henkblanken
    Member
    Posted 8 years ago #

    You're right. Sorry. It returns the same title x times. X being the number of childs.

  6. henkblanken
    Member
    Posted 8 years ago #

    I found the solution here: http://wordpress.org/support/topic/28770?replies=6

    and it works. Thnx anyway!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags