0

So, I've developed a one page theme that pulls in child pages of the parent in order create the layout. I also have it set up to pull each sub pages page template and display the content accordingly, like so.

<?php
/* Template Name: Page- Home */
get_header(); ?>

<?php 
  $this_page=get_query_var('page_id');
  $loop = new WP_Query( array('post_type'=>'page', 'posts_per_page' => -1, 'post_parent' => $this_page, 'orderby' => 'menu_order', 'order' => 'ASC') ); 
  while ( $loop->have_posts() ) : $loop->the_post(); 
  $template = get_post_meta( $post->ID, '_wp_page_template', true );
?>

  <?php include(locate_template($template)); ?>

<?php endwhile; wp_reset_postdata(); ?>

<?php get_footer(); ?>

This works perfectly on the homepage, but I'm running into a problem trying to create another parent page with the same template for the company information. As I said, I have the same code in this new template, but something has gotten messed up, and in the About page, it only displays from the <head> section to the end of my <header>. The footer and beyond doesn't display. What I've found though is that I can comment out the include and it works perfectly.

Any ideas? Thanks!

0

I found the problem here. It was with the $this_page variable, it was referencing the homepage still and kept the about page from working. I had to simply modify how it was pulling the page ID and storing it.

Here's my amended code.

<?php
/* Template Name: Page- Home */
get_header(); ?>

<?php 
  $this_page=get_the_ID();
  $loop = new WP_Query( array('post_type'=>'page', 'posts_per_page' => -1, 'post_parent' => $this_page, 'orderby' => 'menu_order', 'order' => 'ASC') ); 
  while ( $loop->have_posts() ) : $loop->the_post(); 
  $template = get_post_meta( $post->ID, '_wp_page_template', true );
?>  

  <?php include(locate_template(array($template), false, true)); ?>

<?php endwhile; wp_reset_query(); ?>

<?php get_footer(); ?>

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.