Snippets

WordPress Simple Numbered Pagination Without a Plugin

Just place this WordPlace code snippet into a search of archive template.

I see a lot of wordpress sites use plugins and blouted php code to create simple pagination. This useful snippet is actually in the WordPress Codex, It seems alot of people do not know about it.

<?php
global $wp_query;

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
	'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
	'format' => '?paged=%#%',
	'current' => max( 1, get_query_var('paged') ),
	'total' => $wp_query->max_num_pages
) );
?>

Source: http://codex.wordpress.org/Function_Reference/paginate_links...

Share this snippet

 

Comments (6) - Leave yours

  1. Burak Erdem said:

    I couldn’t manage this piece of code work with Blogroll links. I am trying to display all Blogroll links in a single page, 10 posts per page. I am not sure if this code suits for my needs, but I really would love to know how to paginate blogroll links. Thanks.

  2. prshnt said:

    $total = $wpdb->get_var( “SELECT COUNT(country_id) FROM cm_manage_country” );
    $num_of_pages = ceil( $total / $limit );
    $page_links = paginate_links( array(
    ‘base’ => add_query_arg( ‘pagenum’, ‘%#%’ ),
    ‘format’ => ”,
    ‘prev_text’ => __( ‘«’, ‘aag’ ),
    ‘next_text’ => __( ‘»’, ‘aag’ ),
    ‘total’ => $num_of_pages,
    ‘current’ => $pagenum
    ) );

    if ( $page_links ) {
    echo ” . $page_links . ”;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

Please respect the following rules: No advertising, no spam, no keyword in name field. Thank you!