Wordpress - 如何为我的代码添加分页

时间:2016-07-20 20:10:01

标签: php wordpress pagination

<?php
            $wpb_all_query = new WP_Query(array(
                'post_type'=>'post', 'post_status'=>'publish',
                'posts_per_page'=>-1
            ));

            if ( $wpb_all_query->have_posts() ) : ?>

            <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post();
                $cats = get_the_category();
                if ($cats[0]->cat_name !== 'Coaching' && $cats[0]->cat_name !== 'Jobs') { ?>
                <div class="callout horizontal word-wrap"
                     data-category="
                        <?php
                            echo $cats[0]->cat_name;
                        ?>">

                    <?php the_post_thumbnail() ?>

                    <h5><?php the_title(); ?></h5>
                    <?php the_content(); ?>

                </div>
                <?php } ?>
            <?php endwhile; ?>

        <?php endif; ?>

在wordpress中为这些帖子添加分页的最简单方法是什么,每页显示5个帖子?

然后我想使用ajax替换分页以更新显示的帖子。

我正在寻找一个也解释了posts_per_page的答案,因为我认为这是我需要进行分页的。

2 个答案:

答案 0 :(得分:1)

通过这个args你可以显示帖子。

 $posts_per_page = get_option('posts_per_page');

 $args = array('paged'=>$paged,
          'posts_per_page'=>$posts_per_page,
          'post_type'=> 'post',
          'post_status'=>'publish'
          );
  query_posts($args);

然后使用Wp pagination

答案 1 :(得分:0)

转到WP-Admin =&gt; Setting =&gt; Reading

并设置Blog pages show at most = number post you want show in one page

那就是它!

相关问题