在post type archive页面上修改主查询,而不是直接修改主查询,只需使用普通循环(您可以create post type template, 在你的情况下archive-portofolio.php
), 并在过滤器下运行修改查询pre_get_posts
.
正常循环打开archive-portfolio.php
<div class="row text-center small-up-1 medium-up-2 large-up-3 small_section">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="columns">
<div class="box relative">
<a class="overlay" href="<?php the_permalink(); ?>">
<div class="vertical_align">
<h5><?php the_title();?></h5>
<!-- YOUR ANOTHER STUFF -->
</div>
</a>
<?php the_post_thumbnail(); ?>
</div>
</div>
<?php endwhile; ?>
<!-- Pagination Goes Here -->
<div class="row">
<div class="small-12 columns">
<?php
the_posts_pagination( array(
\'mid_size\' => 2,
\'prev_text\' => \'Previous\',
\'next_text\' => \'Next\',
) );
?>
</div>
</div>
<?php else : ?>
<p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php endif; ?>
</div>
在中修改查询帖子类型
functions.php
add_action( \'pre_get_posts\' ,\'wpse222471_query_post_type_portofolio\', 1, 1 );
function wpse222471_query_post_type_portofolio( $query )
{
if ( ! is_admin() && is_post_type_archive( \'portofolio\' ) && $query->is_main_query() )
{
$query->set( \'posts_per_page\', 6 ); //set query arg ( key, value )
}
}