Thursday 25 December 2014

wordpress pagination

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


         CUSTOM PAGINaTION QUERY
<?php 
      $temp = $wp_query; 
      $wp_query = null; 
      $wp_query = new WP_Query(); 
      $wp_query->query('showposts=6&post_type=ad_listing'.'&paged='.$paged); 
   ?> 
                <nav>
     <?php previous_posts_link('&laquo; Newer') ?>
     <?php next_posts_link('Older &raquo;') ?>
    </nav>

    <?php 
      $wp_query = null; 
      $wp_query = $temp;  // Reset
    ?>

No comments:

Post a Comment