有些站长喜欢把最近的留言放到首页上加强互动交流,可以在自己需要显示的位置添加以下代码:
[code]<?php
global $wpdb, $comments, $comment;
$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″); ?>
<h3><?php _e(‘最新评论’) ?></h3>
<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>[/code]
如果需要美化自己在添加CSS样式。