【发布时间】:2017-09-30 20:47:29
【问题描述】:
是否有可能使选择的 gravatar 图像成为唯一会出现在 cmets 中的图像?我的意思是当用户在电子邮件帐户上有自己的头像时发表评论,然后我不希望在该评论中显示他的形象。在发布的 cmets 中,我希望始终是我在 wp 仪表板中设置的一个默认图像。如果可能的话,我该怎么做?谢谢
【问题讨论】:
是否有可能使选择的 gravatar 图像成为唯一会出现在 cmets 中的图像?我的意思是当用户在电子邮件帐户上有自己的头像时发表评论,然后我不希望在该评论中显示他的形象。在发布的 cmets 中,我希望始终是我在 wp 仪表板中设置的一个默认图像。如果可能的话,我该怎么做?谢谢
【问题讨论】:
在您的comments.php 模板中,删除对get_avatar 的所有引用,然后将其替换为图像。这样,任何 cmet 的人都将拥有确切的图像。
更新:
由于您的comments.php 正在调用wp_list_comments 函数,因此您必须对其进行修改并使用自定义回调作为described here。
所以将wp_list_comments(...); 替换为:
wp_list_comments( 'type=comment&callback=mytheme_comment' );
并在您的functions.php 文件中添加:
function mytheme_comment($comment, $args, $depth) {
if ( 'div' === $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
?>
<<?php echo $tag ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
<?php if ( 'div' != $args['style'] ) : ?>
<div id="div-comment-<?php comment_ID() ?>" class="comment-body">
<?php endif; ?>
<div class="comment-author vcard">
<?php /* this is where avatar is displayed */ ?>
<?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
<?php /* remove the above and add something like this */ ?>
<?php echo "<img src='YOUR-IMAGE-URL' class='user-avatar' />" ?>
<?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
</div>
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
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( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div>
<?php if ( 'div' != $args['style'] ) : ?>
</div>
<?php endif; ?>
<?php
}
【讨论】: