Last active
June 26, 2016 12:50
-
-
Save faisalhmohd/91118e09948285c99648573c7f9db34b to your computer and use it in GitHub Desktop.
[Wordpress] Infinite Loop of Posts on Custom Static 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['paged']; | |
$perpage = 15; // Choose the number of posts per loop | |
$args = array ( | |
'pagination' => true, | |
'posts_per_page' => $perpage, | |
'post_type' => 'post', | |
'offset' => $paged*$perpage | |
); | |
$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 post info here | |
endwhile; | |
if ($total_pages > 1){ ?> | |
<div class="navigation"> | |
<a class="next page-numbers" href="/?paged=<?php echo $paged + 1; ?>">Load More</a> | |
</div> | |
<?php } | |
endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment