Hallo,
ich möchte gerne für jeden einzelnen Kommentar eine Nummer ausgeben. Monika hatte für ältere Versionen vor 2.7 eine Lösung, welche hier im dritten Quick-Tipp nachzulesen ist.
Versuche, genau diese Funktion für 2.7.1 einzubauen, sind trotz zahlreicher Anleitungen (im Forum habe ich keine gefunden) bei mir gescheitert.
Die Kommentarschleife ist so angepasst, dass Kommentare und Track-/Pingbacks separat verarbeitet und gezählt werden.
PHP
<?php if ( have_comments() ) : ?>
<?php if ( !empty($comments_by_type['comment']) ) : ?>
<h2 id="comments"><?php comments_number('0 Kommentare', 1 Kommentar', '% Kommentar' );?></h2>
<ol class="commentlist" style="list-style-type: none;">
<?php wp_list_comments('type=comment&callback=list_comments'); ?>
</ol>
<?php endif; ?>
<?php if ( ! empty($comments_by_type['pings']) ) : ?>
<h3 id="pings">Trackbacks/Pingbacks</h3>
<ol class="pinglist">
<?php wp_list_comments('type=pings'); ?>
</ol>
<?php endif; ?>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ('open' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<!-- If comments are closed. -->
<p class="nocomments">Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
Alles anzeigen
Für die Trennung von Kommentaren und Track-/Pingbacks sowie die Anpassung an meinen Theme habe ich folgenden Code in die functions.php meines Themes eingebaut:
PHP
/**
* Kommentare und Track- sowie Pingbacks trennen
*/
function ping_count( $count ) {
global $id;
$comments_by_type = &separate_comments(get_comments('post_id=' . $id));
return count($comments_by_type['pings']);
}
function comment_count( $count ) {
global $id;
$comments_by_type = &separate_comments(get_comments('post_id=' . $id));
return count($comments_by_type['comment']);
}
add_filter('get_comments_number', 'comment_count', 0);
/**
* Kommentarerscheinung anpassen
*/
function list_comments($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
if ( 'div' == $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
} ?>
<<?php echo $tag ?> <?php comment_class() ?> id="comment-<?php comment_ID() ?>">
<?php if ( 'ul' == $args['style'] ) : ?>
<div id="div-comment-<?php comment_ID() ?>">
<?php endif; ?>
<div class="comment-author vcard">
<?php printf(__('<cite>%s sagt:'), get_comment_author_link()) ?>
</div>
<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID, $page ) ) ?>"><?php printf(__('%1$s
at %2$s'), get_comment_date('F jS, Y'), get_comment_time()) ?></a><?php edit_comment_link('Bearbeiten',' ','') ?></div>
<?php comment_text() ?>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
<?php if ( 'ul' == $args['style'] ) : ?>
</div>
<?php endif;
}
Alles anzeigen
Wo habe ich nun anzusetzen?
Für eure Hilfe bedanke ich mich im Voraus.