如果您喜欢简单的模板文件,也可以通过自定义注释回调来实现。
呼叫wp_list_comments()
使用自定义回调处理程序:
wp_list_comments(
array(
\'callback\' => \'custom_comment_callback\',
\'style\' => \'ol\'
)
);
现在让回调函数变得非常简单:
function custom_comment_callback( $comment, $args, $depth )
{
include \'comment-template.php\';
}
现在你可以使用
comment-template.php
与任何其他模板一样。
下面是一个简单的示例,向您展示哪些变量可用:
<?php # -*- coding: utf-8 -*-
print \'<pre>$comment = \' . esc_html( var_export( $comment, TRUE ) ) . \'</pre>\';
print \'<pre>$args = \' . esc_html( var_export( $args, TRUE ) ) . \'</pre>\';
print \'<pre>$depth = \' . esc_html( var_export( $depth, TRUE ) ) . \'</pre>\';
您还可以使用现有回调处理程序的函数体,如此处的“212”中的函数体,它将起作用:
<?php # -*- coding: utf-8 -*-
$GLOBALS[\'comment\'] = $comment;
switch ( $comment->comment_type ) :
case \'pingback\' :
case \'trackback\' :
// Display trackbacks differently than normal comments.
?>
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
<p><?php _e( \'Pingback:\', \'twentytwelve\' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( \'(Edit)\', \'twentytwelve\' ), \'<span class="edit-link">\', \'</span>\' ); ?></p>
<?php
break;
default :
// Proceed with normal comments.
global $post;
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<article id="comment-<?php comment_ID(); ?>" class="comment">
<header class="comment-meta comment-author vcard">
<?php
echo get_avatar( $comment, 44 );
printf( \'<cite class="fn">%1$s %2$s</cite>\',
get_comment_author_link(),
// If current post author is also comment author, make it known visually.
( $comment->user_id === $post->post_author ) ? \'<span> \' . __( \'Post author\', \'twentytwelve\' ) . \'</span>\' : \'\'
);
printf( \'<a href="%1$s"><time datetime="%2$s">%3$s</time></a>\',
esc_url( get_comment_link( $comment->comment_ID ) ),
get_comment_time( \'c\' ),
/* translators: 1: date, 2: time */
sprintf( __( \'%1$s at %2$s\', \'twentytwelve\' ), get_comment_date(), get_comment_time() )
);
?>
</header><!-- .comment-meta -->
<?php if ( \'0\' == $comment->comment_approved ) : ?>
<p class="comment-awaiting-moderation"><?php _e( \'Your comment is awaiting moderation.\', \'twentytwelve\' ); ?></p>
<?php endif; ?>
<section class="comment-content comment">
<?php comment_text(); ?>
<?php edit_comment_link( __( \'Edit\', \'twentytwelve\' ), \'<p class="edit-link">\', \'</p>\' ); ?>
</section><!-- .comment-content -->
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( \'reply_text\' => __( \'Reply\', \'twentytwelve\' ), \'after\' => \' <span>↓</span>\', \'depth\' => $depth, \'max_depth\' => $args[\'max_depth\'] ) ) ); ?>
</div><!-- .reply -->
</article><!-- #comment-## -->
<?php
break;
endswitch; // end comment_type check