在WP主题制作当中,个人感觉comments.php部分的制作是最难最复杂的。下面这个评论列表函数是之前本站自用的,自己改出来主要是添加头像alt属性,以及相应的Gravatar服务器替换。
//评论列表样式
function inlojv_comment_list($comment, $args, $depth) {
$host = 'http://secure.gravatar.com'; // 可以替换为多说服务器:http://gravatar.duoshuo.com,http://www.gravatar.com , https://secure.gravatar.com
$email = get_comment_author_email();
$email_hash = md5( strtolower( trim( $email ) ) );
$out= "$host/avatar/";
$out .= $email_hash;
$out .= '?s=36';
$input_alt = get_comment_author($id);
$tem_url = get_bloginfo("template_url");
echo '<li '; comment_class(); echo ' id="comment-'.get_comment_ID().'">';
echo '<div class="comt-body"'; echo ' id="comment-'.get_comment_ID().'" class="tra">';
//头像
echo '<div class="cl-avatar">';
echo <<<EOF
<img src="{$out}" class="avatar" width="36" height="36" alt="{$input_alt}">
<em></em>
EOF;
echo '</div>';
//评论主体
echo '<div class="cl-main" id="div-comment-'.get_comment_ID().'">';
//信息
echo '<div class="cl-meta">';
if ($comment->comment_type == '') {
$author_link = empty ( $comment->comment_author_url ) ? null : ' href="'. $comment->comment_author_url . '"';
$author = $comment->comment_author;
echo <<<EOF
<span class="cl-author"><a title="{$author}" rel="external nofollow" target="_blank" class="cl-author-url"{$author_link}>{$author}</a></span>
EOF;
}
echo '<span class="cl-time tra">'.get_comment_time( 'Y-n-j H:i' ).'</span>';
if ($comment->comment_approved !== '0'){
echo comment_reply_link( array_merge( $args, array('add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) );
echo edit_comment_link(__('(编辑)'),' - ','');
}
echo '</div>';
//内容
echo '<div class="cl-content" >';
echo convert_smilies(get_comment_text());
if ($comment->comment_approved == '0'){
echo '<span class="cl-approved">您的评论需要审核后才能显示,请稍后!</span><br />';
}
echo '</div>';
echo '</div>';
echo '</div>';
}
将以上函数放在comments.php里面的评论列表回调函数中进行调用即可。
<?php wp_list_comments('callback=inlojv_get_comment_list'); ?>
本站文章除注明转载/出处外,均为本站原创或翻译。若要转载但请务必注明出处,尊重他人劳动成果。
转载请注明出处链接 : https://www.inlojv.com/4451.html
