Code Snippets
posted by Maan

WordPress Pagination Without A Plugin

WordPress Pagination Without A Plugin

WordPress Pagination is a basic need for every websites using WordPress platform. There are many pagination plugin available. In this snippet I’m going to show you How to show WordPress Pagination without a Plugin.

Add the following to functions.php in your theme directory:

if ( ! function_exists( 'my_pagination' ) ) :
	function my_pagination() {
		global $wp_query;
 
		$big = 999999999; // need an unlikely integer
		
		echo paginate_links( array(
			'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
			'format' => '?paged=%#%',
			'current' => max( 1, get_query_var('paged') ),
			'total' => $wp_query->max_num_pages
		) );
	}
endif;

Now you can call the function:

<?php my_pagination(); ?>

View Source →

Maan

21 year old designer, blogger and front-end developer. love to share creative design and inspiration.

  • http://www.DesignYourOwnBlog.com/ Marianne

    So where do you use this? Top of your Blog page with lists of posts? Also, where do you call the function? in page_blog.php?

    • http://www.downgraf.com/ Maan

      First you need to add function in to your theme functions.php and then you need to call the function at the bottom of index.php

    • http://www.DesignYourOwnBlog.com/ Marianne

      Ok thanks. I’m not sure where the pagination is supposed to appear though… at the bottom of posts? Could you provide a screenshot? Thanks for replying to my question!

    • http://www.downgraf.com/ Maan

      Go to your theme folder and find this line previous_posts_link and next_posts_link in index.php, archive.php, category.php, search.php and any other archive page template. and replace it with this:

comments powered by Disqus