Guest User

Untitled

a guest
Jan 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <?php
  2. if ( get_query_var('paged') ) {
  3. $paged = get_query_var('paged');
  4. } elseif ( get_query_var('page') ) { // 'page' is used instead of 'paged' on Static Front Page
  5. $paged = get_query_var('page');
  6. } else {
  7. $paged = 1;
  8. }
  9.  
  10. $custom_query_args = array(
  11. 'post_type' => 'post',
  12. 'posts_per_page' => get_option('posts_per_page'),
  13. 'paged' => $paged,
  14. 'post_status' => 'publish',
  15. 'ignore_sticky_posts' => true,
  16. //'category_name' => 'custom-cat',
  17. 'order' => 'DESC', // 'ASC',
  18. 'orderby' => 'date' // modified | title | name | ID | rand
  19. );
  20. $custom_query = new WP_Query( $custom_query_args );
  21.  
  22. if ( $custom_query->have_posts() ) :
  23. while( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
  24.  
  25. <article <?php post_class(); ?>>
  26. <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
  27. <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
  28. <div><?php the_excerpt(); ?></div>
  29. </article>
  30.  
  31. <?php
  32. endwhile;
  33. ?>
  34.  
  35. <?php if ($custom_query->max_num_pages > 1) : // custom pagination ?>
  36. <?php
  37. $orig_query = $wp_query; // fix for pagination to work
  38. $wp_query = $custom_query;
  39. ?>
  40. <nav class="prev-next-posts">
  41. <div class="prev-posts-link">
  42. <?php echo get_next_posts_link( 'Older Entries', $custom_query->max_num_pages ); ?>
  43. </div>
  44. <div class="next-posts-link">
  45. <?php echo get_previous_posts_link( 'Newer Entries' ); ?>
  46. </div>
  47. </nav>
  48. <?php
  49. $wp_query = $orig_query; // fix for pagination to work
  50. ?>
  51. <?php endif; ?>
  52.  
  53. <?php
  54. wp_reset_postdata(); // reset the query
  55. else:
  56. echo '<p>'.__('Sorry, no posts matched your criteria.').'</p>';
  57. endif;
  58. ?>
Add Comment
Please, Sign In to add comment