• Resolved emmsii

    (@emmsii)


    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!

Viewing 9 replies - 1 through 9 (of 9 total)
  • 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 (https://codex.www.ads-software.com/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?

    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; ?>">

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

    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).

    Thanks so much Kafkaesqui. Really appreciate the help ??

    Thread Starter emmsii

    (@emmsii)

    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?

    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.

    Thread Starter emmsii

    (@emmsii)

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

    Quite similar problems, therefore a single topic. ??

    Thread Starter emmsii

    (@emmsii)

    It works, thanks again. ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to distinguish the newest post?’ is closed to new replies.