• Resolved LearnWebCode

    (@learnwebcode)


    Hi everyone,

    I’m looking to output and style the first post differently than the rest (on the homepage at least). I’m not sure how to achieve this. I searched Google for a few solutions, but I couldn’t get any of them to work.

    I’m assuming it involves a conditional statement. My PHP knowledge is severely lacking but I imagine something with this logic:

    if first post
    –code for first post–

    else
    –regular code for all other posts–

    end

    Am I even close? How do you reference the first post in the If statement? Is this related to the “offset” attribute?

    Any help is greatly appreciated. Also if anyone knows of a link that explains this issue, that would be excellent as well.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter LearnWebCode

    (@learnwebcode)

    I just figured this out.

    In the case that anyone else is looking for the same solution, I’ll explain how.

    I looked for themes that styled the first post differently. I found one and downloaded it, then looked at the “index.php” file to see how it was done. This is the method I’m currently using. I’m sure there is a better way, but I’m not much of a PHP guru, so…

    <?php query_posts('showposts=1'); ?>
    <?php if(have_posts()) : ?><?php while(have_posts()): the_post(); ?>
    your code for first post
    <?php endwhile; ?>
    <?php endif; ?>
    
    <?php query_posts('offset=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
    code for all the other posts
    <?php endwhile; ?>

    Cheers,
    LWC

    Hi!!

    I am using your code to style differently the latest post. It works perfectly but It make problems within paged problems, when I want to go page 2 of the older post, it always go to 1 page.

    what’s wrong?

    thanks!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Modifying the loop to output different code for the first post?’ is closed to new replies.