Friday 10 February 2017

Set pagination codding in wp posts Wordpress

WordPress has the ability to split lists of posts or a single post into multiple pages for "paged" navigation.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$loop = new WP_Query( array(
'post_type' => 'post_type',
'posts_per_page' => 4,
'orderby'=> 'orderBy_attribute',
'paged'=>$paged
) );


Example:



<?php 
// the query to set the posts per page to 3
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => 3, 'paged' => $paged );
query_posts($args); ?>
<!-- the loop -->
<?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
  <!-- rest of the loop -->
  <!-- the title, the content etc.. -->
<?php endwhile; ?>
<!-- pagination -->
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
<?php else : ?>
<!-- No posts found -->
<?php endif; ?>

No comments:

Post a Comment