• hooopla

    (@hooopla)


    I want to display the storytitle for the most recent 3 posts on my site with a different style (sort of like the larger headlines you’d see on the lead articles of a newspaper’s front page).

    I’ve got that mostly working (thanks to Kafkaesque and Root), except that the “top” 3 posts of every page are using the special style, rather than just the top 3 of the first page only.

    Is there a way I can limit this behaviour to the first page only? (I’m using the wonderful WP Paginate plugin, in case that’s relevant.)

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • ifelse

    (@ifelse)

    1. Copy your index.php to home.php
    2. Now remove the special styling from index.php.

    You should now find that only the front page has this styling.

    skippy

    (@skippy)

    Investigate the is_home() conditional template tag. That’s what you need to use.

    Thread Starter hooopla

    (@hooopla)

    Thanks, folks. I’ll work on this using your suggestions.

    Root

    (@root)

    The 2 solutions proposed are alternatives. Both are fine. One involves a php conditional. Glad you are going well.

    Thread Starter hooopla

    (@hooopla)

    Oh, I’m so close! But not quite there.

    I’ve added this to my index…

    <h3 class="<?php
    // format the first 3 posts on the main page with different class
    if ((is_home()) && ($loopcounter < 4)) {
    echo "topPost";
    }
    ?>"><?php the_title(); ?></h3>

    …and it’s doing the right thing. But, is_home apparently refers to the entire main page, even when you’ve got pagination set up to break it into, say, 10-post chunks. That means the code above formats the first 3 posts of each 10-post chunk with the “topPost” style. (See here.)

    Is there a condition I can test for that limits this special style to the first 3 posts of the first 10-post chunk of the main page?

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Styling first 3 posts differently — on first page only!’ is closed to new replies.