从GET_COMMENTS的参数中排除特定的用户ID

时间:2014-12-12 作者:tim daniels

我基本上是在多个页面上使用“最新评论”系统,其中一个特定用户被列为评论的第一个回复(用特殊CSS突出显示),然后在这个“特殊评论”下面列出2-3个普通用户。

我希望将特定用户从普通用户列表中排除,但我无法确定。如果HTML有点混乱,很抱歉,但真正重要的是第二个$args数组。

<?php $args = array(
                \'user_id\' => $curauth->ID,
                \'number\' => 5,
                \'status\' => \'approve\',
                \'parent\' => 0
                );
  $comments = get_comments($args);
  if ( $comments )
   {
 foreach($comments as $c){

echo \'<div id="authorcommentsmain">\';
echo \'<ul id="authorcomments">\';
echo \'<li>\';
echo \'<a id="authorcommentlink" href="\'.get_comment_link( $c->comment_ID ).\'"> \';
echo get_the_title($c->comment_post_ID);
echo \'</a>\';
echo "</br>";
echo "<div id=\'authorcommentslatest\'><div id=\'authorcommentsuserphoto\'>";
echo userphoto($c->user_id, \'\', \'\', array(id => \'latestcommentsprofile\'));
echo "</div>";
echo "<div id=\'authorcommentexcerpt\'> <p>";
echo my_get_comment_excerpt( $c->comment_ID, 80 );
echo "</p></div></div></li>\\n";
echo \'</ul></div>\';



$comment_meta_args2 = array(
                           \'status\' => \'approve\',
                           \'parent\' => intval($parent_comment_id),
                           \'number\' => 1,
                           \'user_id\' => 1,
                           \'order\' => ASC
                           );
$replies2 = get_comments($comment_meta_args2);

$parent_comment_id = $c->comment_ID;
$comment_meta_args = array(
                           \'status\' => \'approve\',
                           \'parent\' => intval($parent_comment_id),
                           \'number\' => 2,

                           \'order\' => ASC
                           );
$replies = get_comments($comment_meta_args);


if ( $replies2)
{

foreach($replies2 as $r2) {

    echo \'<div id="authorcommentsmainSPECIAL">\';
echo \'<ul id="authorcommentsSPECIAL">\';
echo \'<li>\';
echo "<div id=\'authorcommentexcerptSPECIAL\'>";
echo "<div id=\'authorcommentsuserphotoSPECIAL\'>";
echo userphoto_thumbnail($r2->user_id, \'\', \'\', array(id => \'latestcommentsprofileSPECIAL\'));
echo "</div>";
echo    "<div id=\'authorcommentexcerptSPECIALa\'>" .  get_comment_author ($r2->comment_ID) . " says... </div> <div id=\'authorcommentexcerptSPECIALb\'>" . get_comment_excerpt( $r2->comment_ID );
echo "</div></div></li>\\n";
echo \'</ul></div>\';

  }
if ( $replies )
{

foreach($replies as $r) {



echo \'<div id="authorcommentsmain2">\';
echo \'<ul id="authorcomments2">\';
echo \'<li>\';
echo "<div id=\'authorcommentexcerpt2\'>";
echo "<div id=\'authorcommentsuserphoto2\'>";
echo userphoto_thumbnail($r->user_id, \'\', \'\', array(id => \'latestcommentsprofile2\'));
echo "</div>";
echo    "<div id=\'authorcommentexcerpt2a\'>" .  get_comment_author ($r->comment_ID) . " says: </div> <div id=\'authorcommentexcerpt2b\'>" . get_comment_excerpt( $r->comment_ID );
echo "</div></div></li>\\n";
echo \'</ul></div>\';
}   
    }
}
    }




  } else { echo "<p style=\'text-align: center\'> Nothing! </p>\\n";} ?>

1 个回复
最合适的回答,由SO网友:tim daniels 整理而成

看来我得自己解决这个问题。

将$comment\\u meta\\u args和$reply替换为

global $wpdb;
 $comment_meta_args="SELECT * FROM `$wpdb->comments`
 WHERE `comment_approved` = 1
 AND    `comment_parent` = (". intval($parent_comment_id) .")
 AND `user_id` != 1 ORDER BY  comment_date ASC LIMIT 3";

$replies=$wpdb->get_results($comment_meta_args);

结束

相关推荐

COMMENTS_NUMBER打印失败

我想使用模板标记显示帖子上的评论数 <?php comments_number( $zero, $one, $more ); ?> 但是,由于某些原因,此标记不起任何作用,也不会打印到页面上。你可以看看我在http://blog.diginomics.com/bitcoins-innate-regulation/以下是3个模板标记的完整代码片段:author、category和comment: <div class=\