Advertisement
keha76

WordPress Pagination Function v1.00a

Nov 20th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.44 KB | None | 0 0
  1. /**
  2.  * WordPress Pagination
  3.  * If you need pagination for a custom query, insert it into the function as a parameter.
  4.  *
  5.  * Modified version of the snippet found here: http://wp-snippets.com/pagination-without-plugin/
  6.  *
  7.  * @version v1.00a
  8.  * @global $wp_query
  9.  * @param object $query optional custom query
  10.  * @return void
  11.  * @author Kenth Hagström <info@kenthhagstrom.se>
  12.  * @link http://kenthhagstrom.se
  13.  */
  14. function keha76_pagination( $query = '' ) {
  15.  
  16.     if ( ! is_object( $query ) ) {
  17.         global $wp_query;
  18.         $query = $wp_query;
  19.     }
  20.  
  21.     $current = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
  22.  
  23.     if ( get_option('permalink_structure') ) {
  24.         $format = 'page/%#%';
  25.     } else {
  26.         $format = '?paged=%#%';
  27.         if ( ! is_home() )
  28.             $format = '&paged=%#%';
  29.     }
  30.  
  31.     if ( $query->max_num_pages > 1 ) {
  32.  
  33.         $defaults = array(
  34.             'base'         => str_replace( PHP_INT_MAX, '%#%', esc_url( get_pagenum_link() ) ),
  35.             'format'       => $format,
  36.             'total'        => $query->max_num_pages,
  37.             'current'      => max( 1, $current ),
  38.             'show_all'     => false,
  39.             'end_size'     => 1,
  40.             'mid_size'     => 3,
  41.             'prev_next'    => true,
  42.             'prev_text'    => __( 'Prev', 'kah76' ),
  43.             'next_text'    => __( 'Next', 'kah76' ),
  44.             'type'         => 'plain',
  45.             'add_args'     => false,
  46.             'add_fragment' => ''
  47.         );
  48.  
  49.         $args = wp_parse_args( apply_filters( 'keha76_pagination_parameters', $defaults ) );
  50.         echo paginate_links( $args );
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement