Hallo!
I would like to reverse the numbering of user comments. For example: There are 110 comments. The last one is on top. Due its position WP assigns to it the #1. But it should be #110.
There is a little change of the code of comments.php needed. The counting is but to reverse. BUT HOW... Unfortunately I am not a php-professional at all...
Some hints would be great.
Thank you very much.
(latest wp-version!)
You can try the following code ↓
find inside comments template (comments.php)
<?php if ($comments) : ?>
add after it
$cnt = count($comments);
$comments = array_reverse($comments);
next find
<?php endforeach; /* end for each comment */ ?>
add before it ↑
<?php $cnt--; ?>
the comments number is $cnt so just echo it anywhere within $comments foreach loop.
<?php echo $cnt; ?>
Thank you very much!
Unfortunately it doesn't work. Obove the commentar-area the added code is displayed :-(
Here the original code.
<code>
<?php if ($comments) : ?>
<h3 id="comments"><?php comments_number('Keine Kommentare', 'Ein Kommentar', '% Kommentare' );?> to “<?php the_title(); ?>”</h3>
<ol class="commentlist">
<?php $commentnumber = 1?>
<?php foreach ($comments as $comment) : ?>
<li id="comment-<?php comment_ID() ?>" class="<?php echo $oddcomment; /* Style differently if comment author is blog author */ if ($comment->comment_author_email == get_the_author_email()) { echo ' Autorenkommentar'; } ?>">
<div class="cmtinfo"><small class="commentmetadata"></small><cite><?php comment_author_link() ?></cite><em>am <?php comment_date('j. F Y') ?> um <?php comment_time() ?> <?php edit_comment_link('Bearbeiten','',''); ?></em><a>" title=""><span class="number"><?php echo $commentnumber; $commentnumber++;?></span></a></div>
<?php if ($comment->comment_approved == '0') : ?>
<em>Der Kommentar muss noch freigegeben werden.</em>
<?php endif; ?>
<?php comment_text() ?>
<?php /* Changes every other comment to a different class */
if ('alt' == $oddcomment) $oddcomment = '';
else $oddcomment = 'alt';
?>
<?php endforeach; /* end for each comment */ ?>
</code>
The problem you can see here:
http://www.onlzoberurff.info/vertretungsplan/
Hi again!
The solution:
<?php if ($comments) : ?>
<h3 id="comments"><?php comments_number('Keine Kommentare', 'Ein Kommentar', '% Kommentare' );?> to “<?php the_title(); ?>”</h3>
<ol class="commentlist">
<strong><?php $commentnumber = count($comments)?></strong>
<?php foreach ($comments as $comment) : ?>
<li id="comment-<?php comment_ID() ?>" class="<?php echo $oddcomment; /* Style differently if comment author is blog author */ if ($comment->comment_author_email == get_the_author_email()) { echo ' Autorenkommentar'; } ?>">
<div class="cmtinfo"><small class="commentmetadata"></small><cite><?php comment_author_link() ?></cite><em>am <?php comment_date('j. F Y') ?> um <?php comment_time() ?> <?php edit_comment_link('Bearbeiten','',''); ?></em><a href="#comment-<?php comment_ID() ?>" title=""><span class="number"><?php echo $commentnumber; <strong>$commentnumber--</strong>;?></span></a></div>
<?php if ($comment->comment_approved == '0') : ?>
<em>Der Kommentar muss noch freigegeben werden.</em>
<?php endif; ?>
<?php comment_text() ?>
</li>
<?php /* Changes every other comment to a different class */
if ('alt' == $oddcomment) $oddcomment = '';
else $oddcomment = 'alt';
?>
<?php endforeach; /* end for each comment */ ?>
</ol>
Changes: <?php $commentnumber = count($comments)?>
and: $commentnumber--
:-)