Max Lynn
Max Lynn

Reputation: 401

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 .

Upvotes: 0

Views: 130

Answers (2)

ClodClod91
ClodClod91

Reputation: 314

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

Upvotes: 1

Quynh Nguyen
Quynh Nguyen

Reputation: 3009

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!

Upvotes: 0

Related Questions