Advertisement
parkeast

pagination.php

Jan 3rd, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.25 KB | None | 0 0
  1. <?php
  2.     global $wp_query;
  3.     global $wp_rewrite;
  4.    
  5.     if( is_search() ){
  6.         if( (int) get_query_var('page') > 0 ){
  7.             $current = get_query_var('page');
  8.         }else{
  9.             if( (int) get_query_var('paged') > 0 ){
  10.                 $current = get_query_var('paged');
  11.             }else{
  12.                 $current = 1;
  13.             }
  14.         }
  15.         $wp_query = new WP_Query('paged='. $current . '&s='.get_query_var('s') );
  16.  
  17.         $pagination = array(
  18.             'base' => @add_query_arg( 'paged' , '%#%' ),
  19.             'format' => '',
  20.             'total' => $wp_query -> max_num_pages,
  21.             'current' => $current,
  22.             'show_all' => false,
  23.             'prev_next'=> true,
  24.             'prev_text'=> __('&laquo; Previous','cosmotheme'),
  25.             'next_text'=> __('Next &raquo;','cosmotheme'),
  26.             'type' => 'array'
  27.         );
  28.  
  29.         if( $wp_rewrite->using_permalinks() ){
  30.                 $pagination['base'] = user_trailingslashit( trailingslashit(  remove_query_arg( 'search', remove_query_arg( 's', get_pagenum_link( 1 ) ) ) ) . 'page/%#%/', 'paged' );
  31.         }
  32.  
  33.         if( !empty($wp_query->query_vars['s'] ) ){
  34.                 $pagination['add_args'] = array( 's' => urlencode( get_query_var( 's' ) ) );
  35.         }
  36.  
  37.         $pgn = paginate_links( $pagination );
  38.        
  39.         if( !empty( $pgn ) ){
  40.             echo wp_pagenavi();
  41.         }
  42.     }else{
  43.         $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
  44.  
  45.         $pagination = array(
  46.                 'base' => @add_query_arg('paged','%#%'),
  47.                 'format' => '',
  48.                 'total' => $wp_query->max_num_pages,
  49.                 'current' => $current,
  50.                 'show_all' => false,
  51.                 'type' => 'array'
  52.                 );
  53.  
  54.         if( $wp_rewrite->using_permalinks() ){
  55.                 $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 'fp_type' , remove_query_arg( 'type' , remove_query_arg( 's', get_pagenum_link( 1 ) ) ) ) ) . 'page/%#%/', 'paged' );
  56.         }
  57.  
  58.         if( !empty($wp_query->query_vars['s'] ) ){
  59.                 $pagination['add_args'] = array( 's' => urlencode( get_query_var( 's' ) ) );
  60.         }
  61.  
  62.         if( !empty( $wp_query->query_vars['fp_type'] ) ){
  63.                 $pagination['add_args'] = array( 'fp_type' => get_query_var( 'fp_type' ) );
  64.         }
  65.  
  66.         $pgn = paginate_links( $pagination );
  67.         if( $current == 1 ){
  68.             $current--;
  69.         }
  70.  
  71.         if(!empty($pgn)){
  72.             echo wp_pagenavi();
  73.         }
  74.     }
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement