0815

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

How to Number Your Comments Using the Classic Loop

Before, WordPress added the new comments API in version 2.7, the “classic” comment-loop mechanism was used. This loop still works in any version of WordPress, and is useful for extreme formatting of the comment display area. Numbering your comments in the classic loop is as easy as it is in the new-fangled loop. Here’s how:

In your comments.php file, add a counter variable ( <?php $i = 0; ?> ) just above the loop’s foreachstatement, like so:

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

Then, to increment the counter variable with each iteration of the loop, we add another snippet just below the foreach line, like so:

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

Everything is now set. To display the number of comments, simply echo the value of the counter variable anywhere within your comment loop. Here is an example:

There are comments so far!

Source: Digging into WordPress




0