Created
August 21, 2012 04:03
-
-
Save rambuvn/3411400 to your computer and use it in GitHub Desktop.
pagination of wordpress
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
function wallpress_pagenavi( $the_query ) { | |
global $wp_query, $wp_rewrite; | |
//User wordpress function paginate_links to create pagination, see codex.wordpress.org/Function_reference/paginate_links | |
if ( $the_query ) $wp_query = $the_query; | |
$pages = ''; | |
$max = $wp_query->max_num_pages; | |
if ( !$current = get_query_var( 'paged' ) ) $current = 1; | |
$a['base'] = ( $wp_rewrite->using_permalinks() ) ? user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' ) : @add_query_arg( 'paged', '%#%' ); | |
if ( !empty( $wp_query->query_vars['s'] ) ) $a['add_args'] = array( 's' => get_query_var( 's' ) ); | |
$a['total'] = $max; | |
$a['current'] = $current; | |
$total = 0; //1 - display the text "Page N of N", 0 - not display | |
$a['mid_size'] = 5; //how many links to show on the left and right of the current | |
$a['end_size'] = 1; //how many links to show in the beginning and end | |
$a['prev_text'] = '« Previous'; //text of the "Previous page" link | |
$a['next_text'] = 'Next »'; //text of the "Next page" link | |
if ( $max > 1 ){ | |
echo '<div class="pagenav">'; | |
$pages = '<span class="pages">Page ' . $current . ' of ' . $max . '</span>'."\r\n"; | |
echo $pages . paginate_links( $a ); | |
echo '</div>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment