Wordpress最新评论、留言不显示管理员的言论

2018-1-16 20:00| 发布者: admin| 查看: 975| 评论: 0

摘要: 在SQL查询语句里增加 AND user_id !=1 ,这个ID是管理员的,可以在这里查看。//最新评论、留言function recent_comment( $comment_post_ID=0, $get_total=5, $show_author_url=1, $before='li', $after='/li') { glo ...
在SQL查询语句里增加 AND user_id !=1 ,这个ID是管理员的,可以在这里查看。


//最新评论、留言
function recent_comment( $comment_post_ID=0, $get_total=5, $show_author_url=1, $before='<li>', $after='</li>') {
    global $wpdb;
    $is_gb =($comment_post_ID == "0") ? " != 'guestbook' " : " = 'guestbook' ";
    $request="SELECT ID, post_name, comment_ID, comment_content, comment_author_email, comment_author, comment_author_url, comment_date, post_title FROM $wpdb->comments ";
    $request .= " LEFT JOIN $wpdb->posts ON $wpdb->posts.ID=$wpdb->comments.comment_post_ID ";
    $request .= " WHERE post_status IN ('publish','static') AND comment_approved='1' AND $wpdb->posts.post_name ".$is_gb."  AND user_id !=1 ORDER BY comment_ID DESC LIMIT $get_total";
    $comments=$wpdb->get_results($request);
    if ($comments) {
        foreach ($comments as $comment) {
            $email=$comment->comment_author_email;
            $grav_url="http://www.gravatar.com/avatar/".md5($email)."?s=32";
            $comment_author=stripslashes(strip_tags($comment->comment_author));
            $comment_content=utf8Substr(stripslashes(strip_tags($comment->comment_content)),0,150);
            if ($show_author_url == 1 && strlen($comment->comment_author_url) > 12) $comment_author='<a target="_blank" title="访问 '.$comment_author. '的网站" href="' . $comment->comment_author_url . '">' . $comment_author . '</a>';
            $post_title=stripslashes($comment->post_title);
            $comment_date=date("y-m-d H:i",strtotime($comment->comment_date));
            $permalink=get_permalink($comment->ID)."#comment-".$comment->comment_ID;
            $output=$before."\n";
            $output .= '<span class="avatar"><img src="'.$grav_url.'" alt="" /></span>'."\n";
            $output .= '<span class="fn">'.$comment_author.'</span>'."\n";
            $output .= '<span class="date">'.$comment_date.'</span>'."\n";
            $output .= '<span class="txt"><a href="'.$permalink.'" title="'.$post_title.' &raquo; '.$comment_content.'">'.$comment_content.'</a></span>'."\n";
            $output .= $after."\n";
            echo $output."\n";
        }
    }
}

下一篇如何把wordpress友情链接改成双列显示
上一篇不用WordPress Related Posts插件实现相关日志


支持

超赞

难过

搞笑

扯淡

不解

头晕

欠扁

相关阅读

  • 今天点击最高的新闻

  • 一周点击最多的新闻

返回顶部