检查wordpress templating hierarchy 图形从左到右读取。您有自定义的帖子类型products 因此,您可以重写此文件,并且您的代码应该在产品类别中。php,因为您限制了products posts. 类别php类似,但没有此限制。
// Your category-products.php loop should be like this
<!-- Prepare query -->
$your_query = new WP_Query( array(
\'post_type\' => \'products\',
\'posts_per_page\' => 20,
));
if ( $your_query ->have_posts() ) :
while ( $your_query ->have_posts() ) : $your_query ->the_post();?>
<!-- Show a card -->
<a href="<?php the_permalink();?>">
<div class="product">
<div class="image-container">
<?php the_post_thumbnail();?>
</div>
<p class="title"><?php the_title(); ?></p>
</div>
</a>
<!-- loop-end -->
<?php endwhile; ?>
<!-- pagination -->
<div class="col-md-8 post_paginations" style="text-align:center;">
<?php the_posts_pagination( array(
\'mid_size\' => 2,
\'screen_reader_text\' => __( \' \', \'theme_name\' ),
\'prev_text\' => __( \'Previous\', \'theme_name\' ),
\'next_text\' => __( \'Next\', \'theme_name\' ),
) ); ?>
</div>
<!-- Else -->
<?php else : ?>
<h1><?php esc_html_e( \'Sorry, no posts matched your criteria.\' ); ?></h1>
<?php endif; ?>