如果这是一个自定义模板,则需要使用WP Query筛选出一个类别的帖子:
<?php
$args = array(
\'cat\' => \'12\' // Insert category ID here
);
$query = new WP_Query( $args ); ?>
因此,您的代码应该如下所示:
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
$args = array(
\'cat\' => \'12\' // Insert category ID here
);
$query = new WP_Query( $args ); ?>
<?php if ( $query->have_posts() ) : //loop for custom query ?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?> </h1>
</header>
/* Start the Loop */
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<?php
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( \'template-parts/content\', get_post_format() );
endwhile;
the_posts_pagination();
else :
get_template_part( \'template-parts/content\', \'none\' );
endif; ?>
</main><!-- #main -->