Created
June 26, 2016 17:47
-
-
Save faisalhmohd/31c48e2fbce11bf9a70ef03d79f344fe to your computer and use it in GitHub Desktop.
[Wordpress] Infinte loop on all posts page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
$perpage = 5; | |
$args = array ( | |
'pagination' => true, | |
'posts_per_page' => $perpage, | |
'post_type' => 'post', | |
'paged' => $paged | |
); | |
$my_query = null; | |
$my_query = new WP_Query($args); | |
$total_pages = $my_query->max_num_pages; | |
if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post(); | |
// Extract posts information here | |
endwhile; | |
if ($total_pages > 1){ ?> | |
<nav class="page-navigation"> | |
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div> | |
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div> | |
</nav> | |
<?php } | |
endif; | |
wp_reset_query(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment