Last active
August 29, 2015 14:04
-
-
Save carmichaelize/2e018f4d20f9abb7d0c5 to your computer and use it in GitHub Desktop.
Wordpress Query Pagination Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' => __('←'), | |
// 'next_text' => __('→'), | |
'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