Wer das Layout der Kommentare in WordPress Version 2.7 und höher verändern möchte, sieht in der comments.php des verwendeten Themes nur noch den Aufruf der Funktion wp_list_comments(). Mit der Klasse commentlist können natürlich einige Veränderungen am Design gemacht werden, am grundsätzlichen Aufbau aber nicht.
<div class="commentlist">
<?php wp_list_comments(); ?>
</div>
Um ein eigenes Kommentar-Template zu verwenden, muss man den Callback der Funktion wp_list_comments nutzen, in unserem Beispiel hat das Template den Namen mytheme_comment.
<ul class="commentlist">
<?php wp_list_comments('callback=mytheme_comment'); ?>
</ul>
WordPress überprüft jetzt zuerst ob es eine Funktion mit diesem Namen in der functions.php des aktuellen Themes gibt, wenn ja wird diese Funktion ausgeführt.
Wir erstellen nun die Callback-Funktion in der functions.php, das Layout kann komplett an die eigenen Bedürfnisse angepasst werden.
function mytheme_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author vcard">
<?php echo get_avatar($comment,$size='48',$default='<path_to_url>' ); ?>
<?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
</div>
<?php if ($comment->comment_approved == '0') : ?>
<em><?php _e('Your comment is awaiting moderation.') ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php&phpMyAdmin=1fc4bcd49a3t38068ad7 echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),' ','') ?></div>
<?php comment_text() ?>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</div>
<?php
}
Gefunden bei Simon von webdemar.com
3. Mai 2011 um 10:35 Uhr
I like the dear knowledge you offer for your articles. I will be able to bookmark your blog and feature my youngsters test up here generally. I am reasonably sure they are going to be told lots of new stuff here than anyone else!