Frage

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',
 'posts_per_page' => 1,
];

$queryP = new WP_Query( $args );

if ($queryP->have_posts()) {
    while ( $queryP->have_posts() ) : $queryP->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.

War es hilfreich?

Lösung 2

It solved automatically. I think the WordPress version 5.5.1 is full of bugs. Thanks, everyone for your support.

Andere Tipps

From https://wordpress.org/support/article/creating-a-static-front-page/,

Posts Page: (if not already created) create an empty page. Give it a Title that will be used on top of your posts list. This step is mandatory as you are modifying the WordPress default setting. Any other content other than Title will no be displayed at all on this specific page.

So, When you set it as Posts page, Your loop is ignored.

You can set it as static front page (Homepage) or a normal page with custom page template.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit wordpress.stackexchange
scroll top