fauzanjeg

Custom Change Post per Page

Oct 19th, 2021 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. /* Custom Change Post per Page */
  2. function custom_change_post_per_page( $attr, $name, $category ) {
  3.     switch ($name) {
  4.         case 'jnews_category_': /* For Category Page */
  5.             $attr['pagination_number_post'] = 20;
  6.             $attr['number_post'] = 20;
  7.             break;
  8.         case 'jnews_archive_': /* For Archive Page */
  9.             $attr['pagination_number_post'] = 30;
  10.             $attr['number_post'] = 30;
  11.             break;
  12.         case 'jnews_author_': /* For Author Page */
  13.             $attr['pagination_number_post'] = 15;
  14.             $attr['number_post'] = 15;
  15.             break;
  16.     }
  17.  
  18.     return $attr;
  19. }
  20. add_action( 'jnews_get_content_attr', 'custom_change_post_per_page', 99, 3 );
  21.  
  22. function custom_change_post_per_page_by_pre_get_posts( $query ) {
  23.     if ( is_search() ) { /* For Search Page */
  24.         $query->set( 'posts_per_page', 5 );
  25.     }
  26. }
  27. add_action( 'pre_get_posts', 'custom_change_post_per_page_by_pre_get_posts', 99 );
Add Comment
Please, Sign In to add comment