WordPress.org

Ready to get started?Download WordPress

Forums

Help displaying different number of posts_per_page on page 1 (11 posts)

  1. surfsup74
    Member
    Posted 2 years ago #

    I need help making the loop display 5 posts on the first page and then 6 on the subsequent pages. The code example I've added to pastebin enables me to style the latest post differently to the rest (this is important). I need to combine that (styling latest post differently) with the conditional post_per_page (5 on page 1 and 6 on page 2,3, 4 and so on...)

    I've been trying for hours but to no avial - so I'm asking the community for help.

    http://http://pastebin.com/zWZYWF0R

    Thanks

    Dan

  2. surfsup74
    Member
    Posted 2 years ago #

    Sorry my pastebin url didn't work in the last post! Try this...
    http://pastebin.com/zWZYWF0R

  3. esmi
    Forum Moderator
    Posted 2 years ago #

  4. surfsup74
    Member
    Posted 2 years ago #

    Thanks -
    I copied your code but got an error message:

    Parse error: syntax error, unexpected T_VARIABLE in D:\xampp\htdocs\path_to_file\index.php on line 17

    Any ideas why please?

  5. esmi
    Forum Moderator
    Posted 2 years ago #

    Misplaced single quote. Try http://pastebin.com/5xmkTXSc

  6. surfsup74
    Member
    Posted 2 years ago #

    Ah. Thanks. The post per page now works exactly as I wanted - however, every post is now being given the 'first entry' class.

  7. esmi
    Forum Moderator
    Posted 2 years ago #

  8. surfsup74
    Member
    Posted 2 years ago #

    Thanks for that Esmi! Its not quite right though - sorry - I should have explained more clearly. I wanted only the very latest post to be give the class 'first entry' then every other post should be class of 'other-entries'. Using your code all the posts in the first page are given the class 'first entry' and then the post on subsequent pages are given the style 'other-entires', which is not quite right.

    Also - the loop is missing out a post. I currently see the 5 latest posts on page 1 (post 1 - 5) and then on page 2 I see posts 7 - 12. This is missing out post 6 (?).

    Thanks again...

  9. surfsup74
    Member
    Posted 2 years ago #

    I have amended Esmi's code slightly (see pastebin link below) and now have the latest post given the 'first entry' class and every other post 'other-entries' class (as intended).

    The only thing to now resolve is the missing post?! When on the first page of posts I see five posts (say posts number 1-5 - which is correct) however page 2 starts with post number 7 (so it seems to be skipping post number 6).

    Any ideas why please...

    http://pastebin.com/SMabySE9

  10. Coffee4cr
    Member
    Posted 2 years ago #

    I have the same "problem" but the other way around.

    I have 9 post displaying on the first page, and 8 on the next ones. so on page 2, I see my last post of page 1. but it doesn't happen on other pages.

    Here's the reason why, but haven't figured out the way to fix it yet.

    What's happening is when you switch your posts_per_page parameter, WP recalculates its offset from that new parameter.

    So let's say in your case you have 5 on the first page and 6 on subsequent page.

    It's going to show you 1-5 on page 1, but then when you go on page two, and ask for 6 instead, WP will think you had 6 on the first page, hence why you're getting 7-8-9-10-11-12 on your page 2

  11. Coffee4cr
    Member
    Posted 2 years ago #

    found this, http://pastebin.com/51r7PTwb
    and it fixed my problem.

Topic Closed

This topic has been closed to new replies.

About this Topic