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.

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
) );
  • EXCELLENT!!! One less plug-in needed! Thanks for sharing the find!

  • TheLoneCuber

    Should/could this work in the index.php file (where the theme has no archive.php file)?

  • Burak Erdem

    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.

  • Jen

    Can this work on category.php? I tried it there and nothing happened.

  • prshnt

    $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 . ”;

  • Is there a way to remove the Next and Previous text but keep in the ยป

    Thank you ๐Ÿ™‚