There is a function in wordpress called paginate_links() is used to do this.
And here is the code I use on my blog to display page numbers.
<?php
global $wp_query;
$total = $wp_query->max_num_pages;
if ( $total > 1 ) {
echo "<div id=\"pagination\">";
if(!$current_page = get_query_var('paged'))
$current_page = 1;
$perma = get_option('permalink_structure');
$format = empty( $perma ) ? '&page=%#%' : 'page/%#%/';
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => $format,
'current' => $current_page,
'total' => $total,
'end_size' => 2,
'mid_size' => 1,
'type' => 'list'
));
echo "</div>";
}
?>
(@berius)
10 years, 7 months ago
I would like to implement something like this into my theme for blog posts and comments. Is there any tutorial about that ? π
Thx in advance