WordPress.org

Ready to get started?Download WordPress

Forums

Exclude comments from loop (4 posts)

  1. elsnare
    Member
    Posted 1 year ago #

    I'm using a comment rating (karma) plugin to display "top rated comments" list above the standard comment loop.

    In comments.php

    <?php global $wp_query;
    	 $comment_arr = $wp_query->comments; usort($comment_arr, 'comment_comparator');
     wp_list_comments('callback=aaa&page=%orderby=comment_karma', $comment_arr); ?>

    In functions.php

    function comment_comparator($a, $b)
    	{
    	$compared = 0;
    	if($a->comment_karma != $b->comment_karma)
    	{
    		$compared = $a->comment_karma < $b->comment_karma ? 1:-1;
    	}
    	return $compared;
    	}
    	if($a->comment_karma == 0)
    	{
    	$compared = $compared2;
    	}

    Basically the code checks for rating and sorts comments according to the value, the problem is it returns the full list of comments (only sorted via rating), where I would like it only to return comments with > 1 rating.

    Thanks

  2. delmet
    Member
    Posted 1 year ago #

    Hi Elsnare,
    Did you fin a solution? I am having the same question.
    Thank !

  3. elsnare
    Member
    Posted 1 year ago #

    Unfort. I was not able to solve it the "clean" way.

    What I ended up doing is putting a display:none; style on the comments from the top rated loop to hide them completely on the site. Then using the Karma Comments settings I put a display:block!important; style on the high rated comments (so the display:none; was overwritten).

    It works, but like I said it is not a clean way to do this. The "non-rated" comments are hidden, then replaced with rated once (in my case) 5+ more of them are rated by the users.

    Still would like to find a better solution :)

  4. delmet
    Member
    Posted 1 year ago #

    Many thanks! I'll keep you posted if I find an alternate solution.

Topic Closed

This topic has been closed to new replies.

About this Topic