Guest User

Untitled

a guest
Feb 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  2.  
  3. $fp_limit = 3; // first page limit
  4. $limit = 2; // following page limit
  5. $offset = 0; // default offset
  6.  
  7. if( $paged == 1 ) {
  8. $limit = $fp_limit;
  9. } else {
  10. $offset = $fp_limit + ( ($paged - 2) * $limit );
  11. }
  12.  
  13. $args = array(
  14. 'post_type' => 'my_post_type',
  15. 'post_status' => 'publish',
  16. 'offset' => $offset,
  17. 'posts_per_page' => $limit,
  18. 'caller_ get_ posts' => -1, // remove sticky post
  19. 'paged' => $paged,
  20. 'tax_query' => array(
  21. array(
  22. 'taxonomy' => 'my_taxo',
  23. 'field' => 'slug',
  24. 'terms' => array('slug1', 'slug2', 'slug3')
  25. )
  26. )
  27. );
  28. $my_query = null;
  29. $my_query = new WP_Query($args);
  30.  
  31. // basic loop
  32. if( $my_query->have_posts() ) :
  33. while ($my_query->have_posts()) : $my_query->the_post();
  34.  
  35. ...
  36.  
  37. endwhile; endif; // archive loop
  38. if (function_exists('wp_pagenavi')){ wp_pagenavi( array( 'query' => $my_query ) ); }
  39.  
  40. wp_reset_query();
  41.  
  42. <?php
  43.  
  44. if ( have_posts() ) :
  45. // Start the Loop.
  46. while ( have_posts() ) : the_post();
  47.  
  48. ///<---YOUR LOOP--->
  49.  
  50. endwhile;
  51.  
  52. //<---YOUR PAGINATION--->
  53.  
  54. else :
  55.  
  56. //NO POSTS FOUND OR SOMETHING
  57.  
  58. endif;
  59.  
  60. ?>
  61.  
  62. $ppg = get_option('posts_per_page');
  63. $offset = 1;
  64.  
  65. $query->set('posts_per_page', $offset + $ppp);
  66.  
  67. $offset = $offset + ( ($query->query_vars['paged']-1) * $ppp );
  68. $query->set('posts_per_page',$ppp);
  69. $query->set('offset',$offset);
  70.  
  71. function homepage_offset_pagination( $found_posts, $query ) {
  72. $offset = 1;
  73.  
  74. if( $query->is_home() && $query->is_main_query() ) {
  75. $found_posts = $found_posts - $offset;
  76. }
  77. return $found_posts;
  78. }
  79. add_filter( 'found_posts', 'homepage_offset_pagination', 10, 2 );
  80.  
  81. function tax_and_offset_homepage( $query ) {
  82. if ($query->is_home() && $query->is_main_query() && !is_admin()) {
  83. $query->set( 'post_type', 'my_post_type' );
  84. $query->set( 'post_status', 'publish' );
  85. $query->set( 'ignore_sticky_posts', '-1' );
  86. $tax_query = array(
  87. array(
  88. 'taxonomy' => 'my_taxo',
  89. 'field' => 'slug',
  90. 'terms' => array('slug1', 'slug2', 'slug3')
  91. )
  92. );
  93. $query->set( 'tax_query', $tax_query );
  94. $ppp = get_option('posts_per_page');
  95. $offset = 1;
  96. if (!$query->is_paged()) {
  97. $query->set('posts_per_page',$offset + $ppp);
  98. } else {
  99. $offset = $offset + ( ($query->query_vars['paged']-1) * $ppp );
  100. $query->set('posts_per_page',$ppp);
  101. $query->set('offset',$offset);
  102. }
  103. }
  104. }
  105. add_action('pre_get_posts','tax_and_offset_homepage');
  106.  
  107. function homepage_offset_pagination( $found_posts, $query ) {
  108. $offset = 1;
  109.  
  110. if( $query->is_home() && $query->is_main_query() ) {
  111. $found_posts = $found_posts - $offset;
  112. }
  113. return $found_posts;
  114. }
  115. add_filter( 'found_posts', 'homepage_offset_pagination', 10, 2 );
  116.  
  117. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  118. if( $paged == 1 ) {
  119. $limit = 10;
  120. } else {
  121. $limit = 9;
  122. }
  123.  
  124. 'posts_per_page' => $limit,
Add Comment
Please, Sign In to add comment