Created
November 19, 2015 14:49
-
-
Save ewistrand/8934fb1294a765633429 to your computer and use it in GitHub Desktop.
Custom Wordpress loop with pagination
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 | |
/** | |
* Create post loop query | |
*/ | |
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; | |
$args = array( | |
'post_type' => 'post', | |
'orderby' => 'menu_order', | |
'order' => 'ASC', | |
'showposts' => 3, | |
'no_rows_found' => true, | |
'update_post_meta_cache' => false, | |
'update_post_term_cache' => false, | |
'paged' => $paged | |
); | |
$custom_loop = new WP_Query($args); | |
?> | |
<?php while ( $custom_loop->have_posts() ) : $custom_loop->the_post(); ?> | |
<?php // | |
<?php endwhile; // End of the loop. ?> | |
<?php if ($custom_loop->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?> | |
<nav class="prev-next-posts"> | |
<div class="prev-posts-link"> | |
<?php echo get_next_posts_link( 'Older Articles', $custom_loop->max_num_pages ); // display older posts link ?> | |
</div> | |
<div class="next-posts-link"> | |
<?php echo get_previous_posts_link( 'Newer Articles' ); // display newer posts link ?> | |
</div> | |
</nav> | |
<?php } ?> | |
<?php wp_reset_postdata(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment