Some days ago, Frank wrote a post about Custom Pagination without WordPress Plugins. Jay comment, that something like this already exists (since Version 2.1). We don’t know everything. ๐
How do you get it in your template? The best is, if you have a function, which you can use in several templates.
function my_paginate_links() {
global $wp_rewrite, $wp_query;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
$pagination = array(
'base' => @add_query_arg('page','%#%'),
'format' => '',
'total' => $wp_query->max_num_pages,
'current' => $current,
'prev_text' => __('ยซ Previous'),
'next_text' => __('Next ยป'),
'end_size' => 1,
'mid_size' => 2,
'show_all' => true,
'type' => 'list'
);
if ( $wp_rewrite->using_permalinks() )
$pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );
if ( !empty( $wp_query->query_vars['s'] ) )
$pagination['add_args'] = array( 's' => get_query_var( 's' ) );
echo paginate_links( $pagination );
}
In your template only my_paginate_links() will be called. And this is how the output looks like, of course you can adjust it to your liking:
Comments
11 responses to “WordPress Pagination Again”
Hi, good article but it seems not working. The pagination is showen on my test blog but it doesn’t change the page
the URL published is localhost/index.php?page=2 but it doesn’t work
any clue? thx
You know, Paolo, posting links to localhost won’t help much – especially without any added code.
You’re right Cilice but I used exactly the code below in my functions.php and index.php page
I can’t explain much more about the problem… how can I check if something else is wrong? The code posted in this article works for you without any other setting?
thanks
I found the problem…
the line
# ‘base’ => @add_query_arg(‘page’,’%#%’),
should be
# ‘base’ => @add_query_arg(‘paged’,’%#%’),
this way all works fine
cheers Paolo ๐
iยดll try it now ๐
Any idea what the $arg options
‘end_size’ => 1,
‘mid_size’ => 2,
Do?
reference ๐
http://codex.wordpress.org/Function_Reference/paginate_links
Thanks,
Some how i missed that…
I was expecting a nice list detailing each parameter…got in the habit of reading the codex that way. It was in the paragraph.
๐
Hey all,
I’ve worked on this function a little I made it work with pretty URLs as well as ‘ugly’ URLs without needing to change the code! ๐
http://pauladamdavis.com/blog/2010/12/wordpress-pagination-again-again/
@Paul: great, thanks for sharing
Nice work, but ther’s one problem in the search…
When i input text in the search field, for example “music rock”, are generated pages with the articles and is generated as the first: mydomain .com/url?s=music+rock
at this point if I click on the second page, is generated this link instead: mydomain .com/page/2/url?s=musicrock
and give me an error, because the “+” is missing and the words are combined….
Have anyone a nice solution for this?
Sorry for my bad eng ๐