Without any second thought, WP-PageNavi is one such plugin which everyone knows well, which everyone love very much and which everyone wants to get installed in their WordPress website. But, certainly, just like our other snippets tips, for this also, we are having something for you. It’s pretty simple, on copying and pasting the following snippet in your WordPress website, you will be able to have the WordPress pagination active and that too without the use of any plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | global $wp_query; $total = $wp_query->max_num_pages; // only bother with the rest if we have more than 1 page! if ( $total > 1 ) { // get the current page if ( !$current_page = get_query_var('paged') ) $current_page = 1; // structure of "format" depends on whether we're using pretty permalinks $format = empty( get_option('permalink_structure') ) ? '&page=%#%' : 'page/%#%/'; echo paginate_links(array( 'base' => get_pagenum_link(1) . '%_%', 'format' => $format, 'current' => $current_page, 'total' => $total, 'mid_size' => 4, 'type' => 'list' )); } |
Snippet Source/Credit: Smashing Magazine