WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How do you get different Comment look on different Post? (6 posts)

  1. Visedar
    Member
    Posted 6 years ago #

    I want to have a particular Single-Post to list its comments differently (to include a graphic before every posters' names) than the rest of the Posts.

    As you can see in the code below, I've added the IMG tag to display a graphic before the comment poster's name, but the problem is that every other Single-Post and Page will use this same Comment Template (comments.php) and show the same graphic which I don't want.

    <li class="<?php if ( $comment->comment_author_email == get_the_author_email() ) echo 'mycomment'; else echo $oddcomment; ?>" id="comment-<?php comment_ID() ?>">
    <p style="margin-bottom:5px;"><img src="/graphic.gif" border="0"><p>By <?php comment_author_link() ?> on " title=""><?php comment_date('M j, Y') ?> <?php edit_comment_link('Edit',' | ',''); ?></p>
    <?php if ($comment->comment_approved == '0') : ?>
    Your comment is awaiting moderation.
    <?php endif; ?>
    <?php comment_text() ?>

    Any ideas or instructions as how I can achieve this?

  2. Ivovic
    Member
    Posted 6 years ago #

    you're clearly familiar with conditionals, so I'll make this short.

    surround your specific code with an if statement that goes something like...

    <?php if ($post->ID==xxx) : ?>

    [your custom code here]

    <?php endif; ?>

    where xxx is the id of the post you want to display your new pretty stuff on.

  3. Ivovic
    Member
    Posted 6 years ago #

    btw, that works for a specific ID - but if you wanted to do this for a whole category of similar posts, you should check out in_category()

  4. Visedar
    Member
    Posted 6 years ago #

    Thank Ivovic, for your help. You guessed it write, I wanted to do it for a whole category of similar posts. I followed your instructions as well as the "in_category" link, and this is what I came up with:

    <li class="<?php if ( $comment->comment_author_email == get_the_author_email() ) echo 'mycomment'; else echo $oddcomment; ?>" id="comment-<?php comment_ID() ?>">
    <p style="margin-bottom:5px;">
    <?php if ( in_category('speacial') ): ?>
    <img src="/graphic.gif" border="0"><p>
    <?php endif; ?>
    By <?php comment_author_link() ?> on " title=""><?php comment_date('M j, Y') ?> <?php edit_comment_link('Edit',' | ',''); ?></p>
    <?php if ($comment->comment_approved == '0') : ?>
    Your comment is awaiting moderation.
    <?php endif; ?>
    <?php comment_text() ?>

    but it did not work - it entirely removed the IMG from all of the posts as expected but it didn't include the IMG in the post with the defined category, also tried with the Admin user name jsut to see if it will work, but also did not work :S

    Any additional support will be greatly appreciated.

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    in_category is still fairly stupid and only understands category names and/or ID numbers. It's not capable of handling slugs (yet).

    Use the ID number of the category, that usually works.

  6. Visedar
    Member
    Posted 6 years ago #

    WOW! Once I put the category ID number it worked like magic!

    Thank you so much, Otto42 and Ivovic; greatly appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic