简体   繁体   中英

Wordpress - How to add pagination to my code

<?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; ?>

What is the most simplist way to add pagination to these post in wordpress showing 5 posts per page?

I then want to use ajax to replace the pagination to update the posts that are shown.

I'm looking for an answer that also explains the posts_per_page as I thought this is what I would need to make my pagination .

With this args you can display posts.

 $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);

Then use Wp pagination

Go to your WP-Admin => Setting => Reading

And set Blog pages show at most = number post you want show in one page

That's it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM