0815

Du musst dich anmelden um Beiträge und Themen zu erstellen. Einloggen · Registrieren

Alternate Comment Styles

Alternating comments for old versions of WordPress (pre-2.7)
This is one of the oldest tricks in the book, but it is still a favorite. Alternating comment styles is a great way to enhance usability and add some stylistic flair to your comments display. The trick is to add an alternating set of classes — odd or even — to the containing element of each comment. While there are many ways to do this, here is one of the easiest. Open your comments.php and modify the comments loop as follows:

<ul>
	<?php $i = 0; ?>
	<?php foreach ($comments as $comment) : ?>
	<?php $i++; ?>

	<li id="comment-<?php comment_ID(); ?>" <?php if($i&1) { echo 'class="odd"'; } else { echo 'class="even"'; } ?>>
		<?php comment_text(); ?>
	</li>
	<php endforeach; ?>
</ul>

With that code in place, your comments will now have alternating CSS classes with which to apply custom styles to your oddly and evenly numbered comments:

.odd {
	background: white;
	color: black;
	}
.even {
	background: black;
	color: white;
	}

Alternating comments for old versions of WordPress (pre-2.7)
In WordPress 2.7 and better, comments automagically include “odd” and “even” classes for oddly and evenly numbered comments, respectively. This makes it a snap to throw down your own custom CSS styles for each of these classes.

Credit: WordPress Garage (404 link removed 2014/10/22)




0