Guest User

Untitled

a guest
Jul 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. <?php
  2.  
  3. // ...
  4.  
  5. /**
  6. * Tweak Archive pages queries.
  7. * @param object $query
  8. * @return object
  9. */
  10. function tweak_archives( $query ) {
  11. // If this is a Story Type term archive page.
  12. if ( !is_admin() && is_tax( 'story_type' ) && $query->is_main_query() ) {
  13. // Exclude the latest post from the main query without braking pagination.
  14. $ppp = get_option( 'posts_per_page' );
  15. $offset = 1;
  16. // Detect and handle pagination...
  17. if ( $query->is_paged() ) {
  18. // Determine page query offset (offset + current page (minus one) x posts per page)
  19. $page_offset = $offset + ( ( $query->query_vars['paged'] - 1 ) * $ppp );
  20. // Apply adjust page offset
  21. $query->set( 'offset', $page_offset );
  22. } else {
  23. // This is the first page. Just use the offset...
  24. $query->set( 'offset', $offset );
  25. }
  26. }
  27.  
  28. return $query;
  29. }
  30. add_filter( 'pre_get_posts', 'tweak_archives' );
  31.  
  32.  
  33. /**
  34. * Adjusting the offset pagination on the Story Type taxonomy archive.
  35. * @param int $found_posts
  36. * @param object $query
  37. * @return int
  38. */
  39. function adjust_offset_pagination( $found_posts, $query ) {
  40. $offset = 1;
  41. if ( !is_admin() && is_tax( 'story_type' ) && $query->is_main_query() ) {
  42. $found_posts = $found_posts - $offset;
  43. }
  44.  
  45. return $found_posts;
  46. }
  47. add_filter( 'found_posts', 'adjust_offset_pagination', 10, 2 );
Add Comment
Please, Sign In to add comment