有两种方法可以实现WordPress评论显示头像方法,第一种使用代码,第二种使用插件实现。
代码实现侧边栏头像:
找到侧栏模板进行代码修改
模板路径:wp-content/themes/当前使用模板/sidebar.php
[php]代码
<ul> <?php global $wpdb; $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,comment_post_ID, comment_author,comment_author_email,comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,17) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT 10"; $comments = $wpdb->get_results($sql); $output = $pre_HTML; foreach ($comments as $comment) { $output .= "\n<li class='new'>".get_avatar($comment, 32)."<a rel='external nofollow' target='_blank' href=\"". $comment->comment_author_url ."\" >" . $comment->comment_author . "</a> : <br /> <a target='_blank' href=\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "\" title=\"". $comment->comment_author. ":" . $comment->post_title . "\">" . strip_tags($comment->com_excerpt) ."</a></li>"; } $output .= $post_HTML; echo $output; ?> </ul>
其中”comment_author !=’bobsheep’”这段文字实现侧边栏不显示管理员的回复,”$output = convert_smilies($output); “实现符号向表情的转换,”(‘comment_author_email’), 18″中的18是头像的大小
使用WP-RecentComments插件
下载链接:http://downloads.wordpress.org/plugin/wp-recentcomments.zip
使用方法1:激活后直接进入小工具调用即可,配置无需多说.
使用方法2:编辑主题,在需要显示最近评论的地方插入这段代码
<?php wp_recentcomments( ‘administrator=false&smilies=true’); ?>
括号中的是配置参数,更多参数可以看下面的表格。
名称类型描述默认值支持版本
limit整数显示的评论数量51.0 或以上
length整数每条评论摘要的最大长度501.0 或以上
posttrue/false显示日志标题true1.1 或以上
pingbacktrue/false显示 pingback 评论true1.1 或以上
trackbacktrue/false显示 trackback 评论true1.4.3 或以上
trackbacktrue/false显示 trackback 评论true1.4.3 或以上
avatartrue/false显示评论者的头像true1.1 或以上
avatar_size整数评论者头像的尺寸321.1 或以上
avatar_positionleft/right评论者头像的摆放位置left1.1 或以上
avatar_default字符串默认头像文件 1.4.1 或以上
navigatortrue/false显示分页导航按钮true1.3 或以上
administratortrue/false显示管理员的评论true1.4.2 或以上
smiliestrue/false将表情符号转换成图片显示false1.6 或以上
举个例子:administrator=false实现不显示管理员的评论,smilies=true实现表情显示为图片
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。