WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display post different after specific number of posts? (5 posts)

  1. Pajje
    Member
    Posted 2 years ago #

    Is there a way to style/display posts different after a exact number of posts on index page? Lets say i want to style posts differently after post number 9. Only on index page.

  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    either add a counter to the loop, and use a conditonal statement;
    or use the $wp_query->current_post variable with a conditional statement.

    for 'only on index page' look into http://codex.wordpress.org/Conditional_Tags

  3. Pajje
    Member
    Posted 2 years ago #

    alchymyth, is it possible to get som example code? I'm struggling, only get it to work for a specific post number, not for (example) post 9 to 9999.

  4. alchymyth
    Forum Moderator
    Posted 2 years ago #

    is it possible to get som example code?

    please

    tis will depend on the level of 'style/display posts different' and on your existing code.

    very general example:

    <?php if( $wp_query->current_post < 9 ) : ?>
    show post in one way
    <?php else : ?>
    show posts in a differnt way
    <?php endif; ?>

    this could be as simple just within the post div to set a css class for the two groups of posts, or wrapping the full output section so you can have a total diffrent html and oputput structure.

    needs to be within the loop.

  5. Pajje
    Member
    Posted 2 years ago #

    Thank you alchymyth you are very helpful, that did the trick!

Topic Closed

This topic has been closed to new replies.

About this Topic