How-to Tricks Wordpress

Changing post count on home page in WordPress template

Some professional WordPress websites usually have custom post roll layout and different post count on homepage. So this means when you go to second page of post roll you should’t see repeating items as a consequence of another post count than set in ‘Blog pages show at most’ setting in Reading section of Settings in WP-admin.

Solving this problem is a simple code you need to add before wordpress loop in your index.php or home.php:

if ( is_home() ) {
    $posts_home = 9; //Set custom post number to show on home
    if( !is_paged() ){
    } else {
	    if ( get_query_var('paged') != 2 )
    		$offsetting = $posts_home + ( ( get_query_var('paged') - 2 ) * get_query_var('posts_per_page') );
    		$offsetting = $posts_home;
	    query_posts($query_string . "&offset=$offsetting");

Here $posts_home is a custom number of post count to show on homepage.

9 replies on “Changing post count on home page in WordPress template”

Well, that whole string of code appears visibly at the top of my home page now. It worked for about two minutes then everything went back to the way it was.

Any suggestions?

Of course you have to make sure you open php tags if you insert this code into HTML part (should be before

Are you is this working? I tried with it but it is not working. I set $posts_home = 12 and my most post count is 25. When I go to second page, I missed 13 posts and it starts from 25th post to show…

Leave a Reply

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