Show different amount of posts on Wordpress home page than other pages


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. // If we're on the index page, we only want the two first posts.
  3. if ( is_home() && !is_paged() )
  4. query_posts('posts_per_page=2');
  5.  
  6. // If we're within the index archives, we want ten posts per page as usual.
  7. else {
  8. // If we are past the second page, offset by an appropriate amount for the page.
  9. // I'm by no means a math guru; I don't know why this works. Trial & error rocks!
  10. if ( get_query_var('paged') != 2 )
  11. $offsetting = 2 + ( ( get_query_var('paged') - 2 ) * get_query_var('posts_per_page') );
  12.  
  13. // If we're on the second page, offset by two.
  14. else
  15. $offsetting = 2;
  16.  
  17. // Plug it into our query.
  18. query_posts($query_string . "&offset=$offsetting");
  19. }
  20. ?>

URL: http://pastebin.com/f318db5f3

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.