0

I have a decent understanding of Wordpress as well as the Advanced Custom Fields Plugin and I'm trying to write my parent page template right now, but I'm having trouble trying to figure out how I can have my child pages appear in the parent page.

The way my layout is set up, my parent page is filled with a whole bunch of different sections. Each section is created in the dashboard as a page and is associated with a custom template. These sections are also using Advanced Custom Fields for their own respective layout.

What I can't figure out how to do is display the sections. Individually, I can see them just fine and everything is formatted correctly (I mean by going to the a child page in the dashboard and viewing it). I can also successfully have those child templates included in the page. However the custom fields from the children won't display.

Here's a sample of my code from a child page template:

<?php
$post_id = $post->ID;

$bg_type = get_field("bg_type", $post_id);
$style = "";

if($bg_type == "bg-color"){
    $style = "background-color: " . get_field("bg_color", $post_id);
} elseif ($bg_type == "bg-img"){
    $url = get_field("bg_img", $post_id)["url"];
    $wp_index = strpos($url, "wp") - 1;
    $url = substr($url, $wp_index);

    $style = "background-image: url('" . $url . "');";
    $style .= " background -repeat: no-repeat; height: 475px; background-size: cover; background-position: center;";
}

?>

<section style="<?php echo $style ?>">
<div class="container">
<div class="inner-container">

<h1><?php echo get_field("header", $post_id) ?></h1>
<h2><?php echo get_field("subheader", $post_id) ?></h2>

</div>
</div>
</section>

I tried out different ways to get child pages to load and currently have this set up

<?php
if ( $post->post_parent == 0) {
    $pages = get_pages(
        array(
            'sort_column' => 'menu_order',
            'hierarchical' => 0,
            'parent' => $post->ID
        )
    );

    foreach ( $pages as $child_page ){
        $content = $child_page->post_content;
        echo $content;
    }
}

I don't know what else to try and I've googled for hours without much progress.

0

You should look at archives.php. What you trying to do is create a custom post type loop ("pages) in different sections of your template. You have to filter by category, taxonomy, or tags to set up your different groupings.

http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-post-types-archive-page-in-wordpress/

https://stackoverflow.com/questions/30883218/custom-post-type-wordpress-query-by-category

I think this is what I mean: List all posts in custom post type by taxonomy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.