one page wordpress not applying templates when useing The_content

I am building a one page WordPress template. I have created a simple loop that pulls all the pages and displays each one in succession on the same page. It displays the content for each page but dose not apply the template that has been attached to the page.
Here is the loop…

        $args = array(
                'post_type' => 'page',
                'order' => 'ASC'
            );
            $the_query = new WP_Query( $args );         
        ?>
        <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> 

    <?php the_content(); ?>
        <?php endwhile; endif; ?>

Related posts

1 comment

  1. When you use the_content, the function will only return the value for the filed post_content within the table. So the code is working as it is expected.

    Try the following

    if ( have_posts() ){
        while ( $the_query->have_posts() ) {
            $the_query->the_post();
            locate_template( get_template_slug( $post->ID ) )
        }
    }
    

    This code uses the function locate_template to find the template file, and get_template_slug to get the name of the template associated with each page.

    Let me know if this helps.

Comments are closed.