Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress

Aron Macarow
Aron Macarow
1,936 Points

Display child page content on parent page?

I currently have child pages titled by year. Each child page contains an ACF repeater with text/image content.

All Artwork (parent page)

  • 2017 (child page)
  • 2016 (child page)
  • 2015 (child page) ... etc.

I'd like to have a parent page display specific content from all of its child pages in descending order. Is that possible?

I know how to call the child pages individually using their page id. But if I did that, the parent page wouldn't automatically call in new content if a new child page was added.

Any pointers you can provide would be of great help. Thank you!

Right now I have this, which works for the post_title, but I'm just not figuring out how to implement it for the ACF repeater content:

<?php $childArgs = array( 'sort_order' => 'ASC', 'sort_column' => 'menu_order', 'child_of' => get_the_ID() ); $childList = get_pages($childArgs); foreach ($childList as $child) { ?> <div class="child-page"> <h2 class="child-title"><?php echo $child->post_title; ?></h2> <?php if( have_rows('a-gallery') ): ?>

        <div class="grand-works">

        <?php while( have_rows('a-gallery') ): the_row(); 

        // vars
        $image = get_sub_field('a-image');
        $thumbssize = get_sub_field('a-size-thumbs'); 

        ?>

            <?php if( $image ): ?>

                    <img src="<?php echo $image ?>" class="thumbs-work grow <?php echo $thumbssize ?>">

            <?php endif; ?>

        <?php endwhile; ?>

        </div>

    <?php endif; ?>
            <?php echo apply_filters( 'the_content', $child->post_content); ?>
        </div>
    <?php } ?>

Is this questions related to your "How to display custom posts of only one category?" question?