Advertisement
srikat

Untitled

Mar 5th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. add_action( 'pre_get_posts', 'be_change_event_posts_per_page' );
  2. /**
  3.  * Change Posts Per Page for Event Archive
  4.  *
  5.  * @author Bill Erickson
  6.  * @link http://www.billerickson.net/customize-the-wordpress-query/
  7.  * @param object $query data
  8.  *
  9.  */
  10. function be_change_event_posts_per_page( $query ) {
  11.  
  12.     if( $query->is_main_query() && !is_admin() && is_home() ) {
  13.  
  14.         $ppp = get_option( 'posts_per_page' );
  15.        
  16.         $offset = 1;
  17.        
  18.         if ( !$query->is_paged() ) {
  19.             $query->set( 'posts_per_page', $offset + $ppp );
  20.         } else {
  21.             $offset = $offset + ( ($query->query_vars['paged']-1) * $ppp );
  22.             $query->set( 'posts_per_page', $ppp );
  23.             $query->set( 'offset', $offset );
  24.         }
  25.  
  26.     }
  27.  
  28. }
  29.  
  30. function homepage_offset_pagination( $found_posts, $query ) {
  31.     $offset = 1;
  32.  
  33.     if( $query->is_home() && $query->is_main_query() ) {
  34.         $found_posts = $found_posts - $offset;
  35.     }
  36.     return $found_posts;
  37. }
  38. add_filter( 'found_posts', 'homepage_offset_pagination', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement