WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Blog post styling (3 posts)

  1. natehawkes
    Member
    Posted 5 months ago #

    I am creating a custom theme for my site and am looking to create a template for my index.php file where my newest blog post is styled differently from others to highlight it from others, and the following three posts are styled differently still, with older posts in a third style. The first four posts will be similar in style to this: http://insideonline.co.uk/magazine/. I would also be looking to utilize the Infinite Scroll feature in Jetpack and would be looking for all appended posts to have the same style as the older posts.

    My question would be how do I tell my theme to differentiate between the order of posts, setting the first post and the following three posts apart from others? Is there a set function to differentiate the posts?

  2. alchymyth
    Forum Moderator
    Posted 5 months ago #

    you could try to work with the loop counter 'current_post';

    example for a default loop:

    <?php if( $wp_query->current_post == 0 && !is_paged() ) { ?>
    FIRST POST on FIRST PAGE
    <?php } elseif( $wp_query->current_post <= 3 && !is_paged() ) { ?>
    POSTs TWO to FOUR on FIRST PAGE
    <?php } else { ?>
    OTHER POSTs
    <?php } ?>
  3. natehawkes
    Member
    Posted 5 months ago #

    I've just put that code inside my loop and, from what I can see, that has had the exact effect I wanted, even if I use multiple pages. That is perfect, thank you so much.

Reply

You must log in to post.

About this Topic