Posts Tagged ‘WordPress’

WordPress最新评论函数和用法

12.30.2008 by admin - 2 Comments
Posted in 生活

我需要这样的功能,但是找了半天,没有符合我的要求的,于是从中选了一个自己修改如下:

function BX_get_recent_comments($no_comments = 10) {
 global $wpdb;
 $request = “SELECT ID, comment_ID, comment_content, comment_author, comment_author_url, post_title FROM $wpdb->comments LEFT JOIN $wpdb->posts ON $wpdb->posts.ID=$wpdb->comments.comment_post_ID WHERE post_status IN (’publish’,’static’) AND comment_approved = ‘1′ ORDER BY comment_ID DESC LIMIT $no_comments”;
 $comments = $wpdb->get_results($request);
 $output = ”;
 if ($comments) {
  foreach ($comments as $comment) {
   $comment_author = stripslashes($comment->comment_author);
   if ($comment_author == “”) {
    $comment_author = “无名氏”;
   }
   $comment_content = strip_tags($comment->comment_content);
   $comment_content = stripslashes($comment_content);
   $permalink = get_permalink($comment->ID).”#comment-”.$comment->comment_ID;
   $url = $comment->comment_author_url;
   $post_title = $comment->post_title;
   if (empty($url)) {
    $output .= “<li>”.$comment_author.” 评论 “.”“”.$post_title.”””.” 说: “.”<a href=’$permalink’>”.$comment_content.”</a></li>”;
   }
   else {
    $output .= “<li>”.”<a href=’$url’ rel=’external’>”.$comment_author.”</a>”.” 评论 “.”“”.$post_title.”””.” 说: “.”<a href=’$permalink’>”.$comment_content.”</a></li>”;
   }
   $output = convert_smilies($output);
  }
 } else {
  $output .= “<li>暂无评论.</li>”;
 }
 echo $output;
}

调用时可使用如下代码:

<ul class=”posts”>
<?php BX_get_recent_comments(7); ?>
</ul>

解决了blog.zhao18.com重定向到www.zhao18.com的问题

12.09.2008 by admin - 0 Comment
Posted in 生活