wordpress_add

Thursday, 30 January 2014

Pagination in wordpress

Pagination in wordpress

First of all download this plugin

https://codex.wordpress.org/Pagination

than paste this code in any template where you want to show all the posts


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


if you want to show the post of specific category than replace this code in above code at line 2. 

$args = array('cat' => '7','posts_per_page' => 3, 'paged' => $paged );

NOTE : cat=>7 will be any Number ( ID of specific category)

Subscribe Dr-Wordpress for Important Knowledge of wordpress..your's suggestions are most welcomed.


No comments:

Post a Comment