我用过_s 作为模板。注释加载为wp_list_comments( array( \'callback\' => \'_s_comment\' ) );
然后注释的样式为_s_comment(). 这就是你将要使用的。
您可以使用get_current_user_id()
获取当前用户id。
$current_user_id = get_current_user_id();
您可以使用
$comment->user_id
. 然后检查它们是否匹配。
if ( $current_user_id == $comment->user_id )
我所做的两项更改
line 11 和
20.
我已将代码添加到gist 及以下。
<?php
if ( ! function_exists( \'_s_comment\' ) ) :
/**
* Template for comments and pingbacks.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*/
function _s_comment( $comment, $args, $depth ) {
$GLOBALS[\'comment\'] = $comment;
$current_user_id = get_current_user_id();
if ( \'pingback\' == $comment->comment_type || \'trackback\' == $comment->comment_type ) : ?>
<li id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
<div class="comment-body">
<?php _e( \'Pingback:\', \'_s\' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( \'Edit\', \'_s\' ), \'<span class="edit-link">\', \'</span>\' ); ?>
</div>
<?php elseif ( $current_user_id == $comment->user_id ) : ?>
<li id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args[\'has_children\'] ) ? \'\' : \'parent\' ); ?>>
<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
<footer class="comment-meta">
<div class="comment-author vcard">
<?php if ( 0 != $args[\'avatar_size\'] ) { echo get_avatar( $comment, $args[\'avatar_size\'] ); } ?>
<?php printf( __( \'%s <span class="says">says:</span>\', \'_s\' ), sprintf( \'<cite class="fn">%s</cite>\', get_comment_author_link() ) ); ?>
</div><!-- .comment-author -->
<div class="comment-metadata">
<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<time datetime="<?php comment_time( \'c\' ); ?>">
<?php printf( _x( \'%1$s at %2$s\', \'1: date, 2: time\', \'_s\' ), get_comment_date(), get_comment_time() ); ?>
</time>
</a>
<?php edit_comment_link( __( \'Edit\', \'_s\' ), \'<span class="edit-link">\', \'</span>\' ); ?>
</div><!-- .comment-metadata -->
<?php if ( \'0\' == $comment->comment_approved ) : ?>
<p class="comment-awaiting-moderation"><?php _e( \'Your comment is awaiting moderation.\', \'_s\' ); ?></p>
<?php endif; ?>
</footer><!-- .comment-meta -->
<div class="comment-content">
<?php comment_text(); ?>
</div><!-- .comment-content -->
<?php
comment_reply_link( array_merge( $args, array(
\'add_below\' => \'div-comment\',
\'depth\' => $depth,
\'max_depth\' => $args[\'max_depth\'],
\'before\' => \'<div class="reply">\',
\'after\' => \'</div>\',
) ) );
?>
</article><!-- .comment-body -->
<?php
endif;
}
endif; // ends check for _s_comment()