Skip to content

Instantly share code, notes, and snippets.

@carmichaelize
Last active August 29, 2015 14:04
Show Gist options
  • Save carmichaelize/2e018f4d20f9abb7d0c5 to your computer and use it in GitHub Desktop.
Save carmichaelize/2e018f4d20f9abb7d0c5 to your computer and use it in GitHub Desktop.
Wordpress Query Pagination Function
<?php
function sc_pagination( $query ){
$string = "";
if( !$query ){
global $wp_query;
if( $wp_query->max_num_pages > 1 ){
//Get current page and query type.
$current_page = max( 1, get_query_var('paged') );
$query_type = isset( $_GET['s'] ) ? '&' : '?';
$args = array(
'base' => esc_url(get_pagenum_link())."{$query_type}paged=%#%",
'format' => "{$query_type}paged=%#%",
'total' => $wp_query->max_num_pages,
'current' => max( 1, get_query_var('paged') ),
'show_all' => true,
//'end_size' => 1,
//'mid_size' => 2,
//'prev_next' => True,
//'prev_text' => __('« Previous'),
//'next_text' => __('Next »'),
'type' => 'list',
//'add_args' => False,
//'add_fragment' => ''
);
$string = paginate_links($args);
}
} else {
if( $query->max_num_pages > 1 ){
$args = array(
'base' => @add_query_arg('pp', '%#%'),
'format' => "pp=%#%",
'total' => $query->max_num_pages,
'current' => max( 1, isset($_GET['pp']) ? $_GET['pp'] : 1 ),
'show_all' => true,
//'end_size' => 1,
//'mid_size' => 2,
//'prev_next' => True,
// 'prev_text' => __('&larr;'),
// 'next_text' => __('&rarr;'),
'type' => 'list',
//'add_args' => true,
//'add_fragment' => ''
);
$string = paginate_links($args);
}
}
return $string;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment