Forums

[resolved] Highlighting comment author on 2.7 with .bypostauthor (7 posts)

  1. baal666
    Member
    Posted 3 years ago #

    Hi,

    I'm having some fun toying with 2.7 new possibilities...

    I was able to get alternating comments styles by using .odd and .even, but the .bypostauthor does not override them so I don't see different colors when I am the author.

    Here is my code:

    <?php if ( have_comments() ) : ?>
    
    	<?php
    		/* Count the totals */
    		$numPingBacks = 0;
    		$numComments  = 0;
    
    		/* Loop through comments to count these totals */
    		foreach ($comments as $comment) {
    			if (get_comment_type() != "comment") { $numPingBacks++; }
    			else { $numComments++; }
    		}
    
    	?>
    
    	<?php 
    
    	/* This is a loop for printing comments */
    	if ($numComments != 0) : ?>
    		<ol class="commentlist">
    		<li class="commenthead"><h2 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h2></li>
    
    	<?php wp_list_comments(); ?>
    
    	</ol>
    
    	<?php endif; ?>

    and the css:

    .bypostauthor{
    background-color: #E9B5C1; }
    
    .odd {
    background-color: #EDC0CB; }
    
    .even {
    background-color: #7BCB94; }

    Anyone can help me?

    Thanks

  2. Jeremy Clark
    Moderator
    Posted 3 years ago #

    Put .bypostauthor last. Cascading Style Sheets means that rules are applied in order from from the beginning and can be overwritten by later rules.

  3. baal666
    Member
    Posted 3 years ago #

    Thanks a lot Jeremy! You solved my problem!

    Just a last question while you're here: how do I customize the comments now with 2.7? With 2.6 and below I would change manually everything in comments.php, but now it seems it is all inside the wp_list_comments() finction...

    I mean, I want to replace "Says" by something else, change some other things that can't be done in CSS, etc.

  4. Jeremy Clark
    Moderator
    Posted 3 years ago #

    You have to use something called a "callback" I've written a little guide for it click on my name and it you'll see the post on the front page.

  5. baal666
    Member
    Posted 3 years ago #

    Thanks! I'll read this carefully.

  6. baal666
    Member
    Posted 3 years ago #

    Very interesting post you have there.

    If you have some free time, I wasn't sure how to set things to work and I let a comment.

  7. baal666
    Member
    Posted 3 years ago #

    Is it possible to do the same trick with 2.6? I mean, how to set odd, even and postauthor correctly?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.