Loop inside page template not working

Question

I am facing a problem with the loop inside the page template. Here is the code.

<?php
/* Template Name: Blog-Template */

get_header();

$args = [
 'post_type' => 'post',
 'post_status' => 'publish',
 'posts_per_page' => 1,
];

$posts = new WP_Query( $args );

while ( $posts->have_posts() ) : $posts->the_post();
 ?>
 <article>
    <?php

    the_title( '<h1>', '</h1>' );
    the_excerpt();

    ?>
 </article>
<?php
endwhile;
get_footer();

If I set this page as a blog page in settings then no problem happens. But when I create a custom loop for this template it doesn’t work. It shows nothing just header and footer.

0
, Raashid Din 2 years 2020-09-01T09:10:41-05:00 0 Answers 49 views 0

Leave an answer

Browse
Browse