这是来自于blog.txt主题里调用最新评论的方法。
把它提出来因为我在用这个东西。在你不想用插件来实现最新评论调用的时候,可以考虑用用这个,否则用Recent Comments这个插件。
直接放代码参考研究吧:
1 2 3 4 5 6 7 8 9 10 11 12 | <?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> |
演示可以看我博客侧边栏,感觉这个对于普通应用还是够了,也可以增删部分你需要或者不需要的东西。
复制代码的时候请注意下符号全半角的事情。
来看看!~
呵呵,正准备换主题!
回复
非常感谢!用了你的code,一下搞定。
刚才没提交上?
回复
Bssn Reply:
1月 2nd, 2010 at 10:19 下午
@Corey, 能用到就好,呵呵。
回复
呵呵,已经用上了 直接放进sidebar里,感谢分享
回复
Bssn Reply:
12月 5th, 2009 at 10:09 下午
@nothing, 使用愉快。
回复
好用,顶一个!
回复
Bssn Reply:
9月 7th, 2009 at 10:54 下午
@applezqp, 谢谢支持!
回复
恩 我也是这个方法!!
回复
Bssn Reply:
6月 6th, 2009 at 11:37 上午
@随影, 缘分啊。
回复
正想要这个,多谢啊。
回复