从英文wp到中文,从英文模板到中文模板,新手也能自学wordpress,经过自己的努力和朋友的帮助,花了1天的时间终于汉化出了一款属于自己的模板,但是发现自己的模板有点问题,右边栏在后台小工具里添加有点错误,如果添加小工具则现有的调用全部消失,如果不添加评论的调用,又显的没什么特点,于是自己在网上搜集资料,测试在侧边栏实现了带 gravatar 头像的最新评论.完善 WordPress 带头像的最新评论的时候,又发现头像有点大,感觉不是太好,先这样吧,后面在慢慢调整,大体是出来了.
WordPress侧边栏调用最新评论,在下面给大家提供三款代码供大家使用.
第一种:gravatar 头像的最新评.通用版:(管理员名称出,输入管理员昵称,已达到过滤管理回复的效果)
03 |
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved,comment_author_email, comment_type,comment_author_url, SUBSTRING(comment_content,1,25) 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 comment_author != '管理员名称' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT 10"; |
04 |
$comments = $wpdb->get_results($sql); |
06 |
foreach ($comments as $comment) { |
07 |
$output .= "\n<li>".get_avatar(get_comment_author_email('comment_author_email'), 18). " <a href=\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "\" title=\"" . $comment->post_title . " 上的评论\">". strip_tags($comment->comment_author) .": ". strip_tags($comment->com_excerpt) ."</a></li>"; |
09 |
$output .= $post_HTML; |
10 |
$output = convert_smilies($output); |
第二种:gravatar 头像缓存版的
03 |
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved,comment_author_email, comment_type,comment_author_url, SUBSTRING(comment_content,1,25) 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 comment_author != '管理员名称' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT 10"; |
04 |
$comments = $wpdb->get_results($sql); |
06 |
foreach ($comments as $comment) { |
07 |
$output .= "\n<li><img width=\"18\" height=\"18\" src=\"http://wange.im/gravatar/cache/avatar/".md5(strtolower($comment->comment_author_email)). " \" /><a href=\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "\" title=\"" . $comment->post_title . " 上的评论\">". strip_tags($comment->comment_author) .": ". strip_tags($comment->com_excerpt) ."</a></li>"; |
09 |
$output .= $post_HTML; |
10 |
$output = convert_smilies($output); |
第三种:最普通的调用方式,只显示ID和留言内容
03 |
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, |
04 |
comment_post_ID, comment_author, comment_date_gmt, comment_approved, |
05 |
comment_type,comment_author_url, |
06 |
SUBSTRING(comment_content,1,18) AS com_excerpt |
08 |
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) |
09 |
WHERE comment_approved = '1' AND comment_type = '' AND |
11 |
ORDER BY comment_date_gmt DESC |
13 |
$comments = $wpdb->get_results($sql); |
15 |
foreach ($comments as $comment) { |
16 |
$output .= "\n<li><strong>".strip_tags($comment->comment_author) |
17 |
."</strong>:" . " <a href=\"" . get_permalink($comment->ID) . |
18 |
"#comment-" . $comment->comment_ID . "\" title=\"on " . |
19 |
$comment->post_title . "\">" . strip_tags($comment->com_excerpt) |
21 |
} $output .= $post_HTML; |
20% off Hosting at GoDaddy.com - World's largest Web host!
Domain Sale! $7.49 .com at GoDaddy
声明:本文发表于乱舞春秋(www.20blog.cn),转载请注明出处:http://www.20blog.cn/2010/07/2114.html,谢谢!有任何问题请联系QQ37750965
标签:
Wordpress,
博客不错,收藏之。