Support » Themes and Templates » ‘Alt’ styled comments

  • Resolved Jaabi


    I’ve recently converted my comments style from WordPress 2.6 to 2.7 formatting by moving the comment layout to the functions.php file as mentioned here.
    The reason for this is simple, I wanted to split my comments into pages.
    However while doing this allowed this to work, my comments stopped using their “alt” styles (flipping alignment of text and avatar), which I learnt from following this page.

    At first I discovered the lines

    <?php foreach ($comments as $comment) : ?>


    $oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : '';?>
    <?php endforeach; /* end for each comment */ ?>

    would either cause comments not to show up at all, or would just produce a blank screen. (Why isn’t PHP telling me the error?)
    Reading around it seems that “alt” is now built into the comments. But yet, my comments do not alternate no matter what I try.

    This is what is in the functions.php file:

    function mytheme_comment($comment, $args, $depth) {
    $GLOBALS['comment'] = $comment; ?>
    <li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">
    <div id="commentavatar"><?php echo get_avatar( $comment, 64 ); ?></div>
    <div class="commentbg">
    <div id="actualtext">
    <h3><?php comment_author_link() ?></h3>
    <?php comment_text() ?>
    <span class="date"><img src="<?php echo get_option('siteurl'); ?>/../layout/comment_time.png" alt="" /> <a href="#comment-<?php comment_ID() ?>" title=""><?php comment_time() ?> on <?php comment_date('F jS, Y') ?></a></span> <?php edit_comment_link('edit','&nbsp;&nbsp;',''); ?>
    <?php if ($comment->comment_approved == '0') : ?>
    <em>Your comment is awaiting moderation.</em>
    <?php endif; ?>
    <?php }?>>

    Called via wp_list_comments in the comments.php

    What do I have to do to get the .alt style value to be used in ‘odd’ comments again?

    EDIT: One more thing, though I am unsure this is possible. Does WP record if a post was made by an unregistered guest? The Admin panel doesn’t seem to differentiate comments any more than just by the name of the poster.
    I was wondering (after the above is sorted) if I can make it so all guest posts get labeled as written by a guest rather than what the guest writes as their name, but I can still see that name in the admin panel.

Viewing 6 replies - 1 through 6 (of 6 total)
  • esmi


    Forum Moderator

    The comments are given class of ‘even’ and ‘odd’ alternately, so it might just be easier to use these built-in classes for your alternate CSS.

    ol.commentlist li.even {…}
    ol.commentlist li.odd {…}

    I thought of that lying in the dark last night, and was all “oh man I’m stupid”.

    However that made no difference. Huh?

    #commentavatar img {
    	position: absolute;
    	margin: 16px;
    	padding: 0px;
    	margin-right: auto;
    	background: #FF0000;
    	z-index: 70;
    ol.commentlist {
    	margin-top: 28px;
    #actualtext {
    	position: relative;
    	margin-top: -78px;
    	margin-left: 116px;
    	margin-right: 24px;
    	z-index: 70;
    .commentlist cite {
    	background: url("/layout/comment_bg1-1.png") no-repeat;
    	height: 100px;
    	position: relative;
    	z-index: 40;
    .commentlist .commentbg {
    	float: right;
    	width: 500px;
    	margin-top: 0px;
    	margin-left: auto;
    	margin-bottom: 14px;
    	padding-bottom: 2px;
    	background: url("/layout/comment_bg1-2.png");
    	z-index: 30;
    .commentlist li {
    	background: url("/layout/comment_bg1-3.png") bottom no-repeat;
    	overflow-x: hidden;
    	position: relative;
    	z-index: 40;
    li.odd cite {
    	background: url("/layout/comment_bg2-1.png") no-repeat;
    li.odd .commentbg {
    	background: url("/layout/comment_bg2-2.png");
    ol.commentlist li.odd {
    	background: url("/layout/comment_bg2-3.png") bottom no-repeat;
    li.odd #actualtext {
    	margin-left: 24px;
    	margin-right: 116px;
    li.odd #commentavatar img {
    	margin-left: 424px;



    Forum Moderator

    I’d really need to see a page of comments on your site.

    I can’t provide a direct link because I’m trying to get everything done (or rather a much bigger portion of material than the current design) before uploading it all.

    Here is a screenshot of before I allowed for paging.
    Now, only the top style appears.

    Alternatively here is a zip file containing most of what I think drives my layout.

    Note I am using a /category/postname/ permalink format, and the “blog” root is set to go to the site root rather than /updcmc/

    Apologies if this is a problem this way.

    blargh double post *nukes*

    Aha. I discovered my problem when looking at another custom theme.

    I did not have

    <?php comment_class(); ?>

    in my li tag in the comment code in functions.php. I did find it odd that no class (most of my styles are id based) was being applied to any comment.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘‘Alt’ styled comments’ is closed to new replies.