WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to distinguish the newest post? (10 posts)

  1. emmsii
    Member
    Posted 8 years ago #

    Hi.

    I want to distinguish the first post on my WordPress blog. It's actually easy: body#home .entry-1 { styles }

    But doing so, the first post looks different on all pages. Is there a solution to distinguish only the newest post?

    Thank you!

  2. Kutitots
    Member
    Posted 8 years ago #

    Yeah, how do you do that? I was thinking of using queries for this one (multiple loops), but the thing is, the example found on the Support pages is distinguishing a post from a specific category. All I want to do is to distinguish the latest post from ANY category. I guess that's the same thing emmsii wants to do?

    This is a shot in the dark, please correct me if I'm wrong. If I change the first query on the code found in Step 1 of multiple loops in action (http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_3_-_Plugins), to this code:

    query_posts('showposts=1');

    ... and then follow the rest of the instructions on Step 2, do think it will work?

  3. Kafkaesqui

    Posted 8 years ago #

    Using query_posts() here is somewhat overkill.

    You can provide a different class to your first post by adding this inside The Loop but before the <div> or whatever it is you're assigning the class to:

    <?php $postclass = ($post == $posts[0]) ? 'entry-1' : 'entry'; ?>

    Then where you have your class:

    <div class="<?php echo $postclass; ?>">

  4. Kutitots
    Member
    Posted 8 years ago #

    Ahhhh! I see. So it's kind of like similar to the way the alternating comment styles is structured (but simpler of course)?

  5. Kafkaesqui

    Posted 8 years ago #

    That's a great comparison. Yes, instead of alternating by testing on say $postclass here, we're just looking to see if the first post ($posts[0]) is the same as the current one ($post).

  6. Kutitots
    Member
    Posted 8 years ago #

    Thanks so much Kafkaesqui. Really appreciate the help :)

  7. emmsii
    Member
    Posted 8 years ago #

    Thanks!

    New problem:
    How to visually distinguish my own comment? At the moment I have such a line: <?php if((get_comment_author() == "my-name")) { $oddcomment = "own"; } ?>

    But if anyone else submits a comment under name "my-name", their comments will be also distinguished. How to solve that? Is there a possibility to check whether the author is registered (2 conditions must be filled: author name "my-name" AND registered user)? Or is there a better way?

  8. Kafkaesqui

    Posted 8 years ago #

    If you are logged in when adding comments, WordPress should be saving your user ID with them. So you can modify the if statement to test on that. There's no template tag for this bit of information, so we have to *pull* it from the $comment array:

    if($comment->user_id == 1)

    Change 1 to your user ID (if different).

    As an aside, when you have a "new problem" it's better to begin a new thread on the forums. Often your new issue goes unnoticed, especially when the original topic was resolved.

  9. emmsii
    Member
    Posted 8 years ago #

    Ok, thanks. I'll test it later and let you know.

    Quite similar problems, therefore a single topic. :)

  10. emmsii
    Member
    Posted 8 years ago #

    It works, thanks again. :)

Topic Closed

This topic has been closed to new replies.

About this Topic