WordPress获取最新评论无插件版
这是来自于blog.txt主题里调用最新评论的方法。
把它提出来因为我在用这个东西。在你不想用插件来实现最新评论调用的时候,可以考虑用用这个,否则用Recent Comments这个插件。
直接放代码参考研究吧:
<?php global $wpdb, $comments, $comment;
// Mini-function for blog.txt recent comments
$comments = $wpdb->get_results(”SELECT comment_author, comment_author_url, comment_ID, comment_post_ID, SUBSTRING(comment_content,1,65) AS comment_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 5″); ?>
<ul><li>
<h2><?php _e(’最新评论’) ?></h2></li>
<ul id=”recentcomments”><?php
if ( $comments ) : foreach ($comments as $comment) :
echo ‘<li class=”recentcomments”>’ . sprintf(__(’<span class=”comment-author vcard”>%1$s</span> <span class=”comment-entry-title”>on <cite title=”%2$s”>%2$s</cite></span> <blockquote class=”comment-summary” cite=”%3$s” title=”Comment on %2$s”>%4$s …</blockquote>’),
‘<a href=”‘. get_permalink($comment->comment_post_ID) . ‘#comment-’ . $comment->comment_ID . ‘” title=”‘ . $comment->comment_author . ‘ on ‘ . get_the_title($comment->comment_post_ID) . ‘”><span class=”fn n”>’ . $comment->comment_author . ‘</span></a>’,
get_the_title($comment->comment_post_ID),
get_permalink($comment->comment_post_ID),
strip_tags($comment->comment_excerpt) ) . ‘</li>’;
endforeach; endif; ?></ul>
</li>
</ul>
演示可以看我博客侧边栏,感觉这个对于普通应用还是够了,也可以增删部分你需要或者不需要的东西。
复制代码的时候请注意下符号全半角的事情。















Yacca
把这些函数都写在Functions.php里 然后调用出来 和插件也差不多了 哈哈
[回复]
Bssn Reply:
August 25th, 2008 at 3:34 pm
碰巧我这个模板没有function,也就懒得再那啥了,哈哈。
[回复]
underone
这个实用。。。。。。。。。。。
[回复]
Bssn Reply:
August 25th, 2008 at 10:34 pm
实用拿去,但需留下你的身子。。。。。
[回复]
Showfom
申请链接,不知道到哪里申请 发你邮件了,呵呵。
Showfom’s Blog
http://www.showfom.com/
已经做好贵站链接。
[回复]
Poshi
哇,留下你的身子?很那个的说法…..
不过,代码够长的,要研究一下怎么去掉一些~~~
似乎本人也喜欢能不用插件就不用插件~~`
[回复]
Bssn Reply:
August 28th, 2008 at 3:47 pm
恩,你多多研究,出来成品我过去捧场。
[回复]
锐风
唉, 够麻烦..
[回复]
锐风
出现问题..
[回复]
Bssn Reply:
August 30th, 2008 at 6:29 pm
WordPress评论的时候老是出来这情况。
[回复]
geuro
正想要这个,多谢啊。
[回复]