显示更多 post stanleywp 主题 WordPress

Show more post stanleywp theme WordPress

我正在使用 WordPress 的 stanleywp 主题来显示一些 post,实际上我已经插入了 20 post,但它只显示了 10post。

这是我所做的:

  1. 投资组合 -> 投资组合类别 -> 我添加了 "brands" 类别

  2. 投资组合 -> 添加新的 -> 我添加了 20 post 并设置了 "brands" 类别

当我去 .../portfolio-category/brands/ 时,我应该看到我所有的 20 post,但我只看到 10。

我该如何解决?

这是taxonomy-portfolio_cats.php:

<?php
/**
 * @package WordPress
 */
?>

<?php get_header(); ?>
<?php if (have_posts()) : ?>


   <div class="container pt">

      <div class="row mt">
        <div class="col-lg-6 col-lg-offset-3 centered">
           <h1><?php echo single_term_title(); ?></h1>
           <hr>
           <?php if(category_description()) { ?>
           <?php echo category_description( ); ?>
           <?php } ?>
       </div>
   </div>

   <div class="row mt centered">
    <?php $cont = 0; ?>
    <?php while (have_posts()) : the_post(); ?>

    <div class="col-lg-4">
       <?php if ( has_post_thumbnail()) : ?>
       <a class="zoom green" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
          <?php the_post_thumbnail(); ?>
      </a>
  <?php endif; ?>

  <?php if(bi_get_data('project_title', '5')) {?>
  <p><?php the_title(); ?></p>
  <?php } ?>
</div> <!-- /col -->

<?php endwhile; ?>
<?php wp_reset_query(); ?>

</div>


<?php endif; ?>
<?php get_footer(); ?>

我认为这是由于默认分页(每页 10 个帖子)造成的:您可以增加 Settings > Reading > Blog pages show at most 的值,或者在 <?php wp_reset_query(); ?> 之后插入分页,例如:

<?php
// Previous/next page navigation.
the_posts_pagination( array(
    'prev_text'          => __( 'Previous page', 'your-textdomain' ),
    'next_text'          => __( 'Next page', 'your-textdomain' ),
    'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'your-textdomain' ) . ' </span>',
) );
?>

或者,如果您只想更改该分类存档的每页帖子数,您可以使用 pre_get_posts action:

function portfolio_cats_posts_per_page( $query ) {
    if ( is_admin() || ! $query->is_main_query() )
        return;

    if ( is_tax( 'portfolio_cats' ) ) {
        // Display all posts in one page
        $query->set( 'posts_per_page', -1 );
    }
}
add_action( 'pre_get_posts', 'portfolio_cats_posts_per_page', 1 );