I feel guilty to ask something again in this topic, but it seems to me this is the best place to ask it.
As seen above I use this code to show the post score:
<?php
$counts = aigoo_get_score();
extract( $counts ); //restores compacted variables
<span>+'.$score.'</span>
?>
The following code is showing the latest 5 posts with the most comments in a specific category on my homepage:
<?php
$popular = new WP_Query( array(
'post_type' => array( 'post' ),
'showposts' => 5,
'cat' => 'activiteit',
'ignore_sticky_posts' => true,
'orderby' => 'comment_count',
'order' => 'dsc',
'date_query' => array(
array(
'after' => '0',
),
),
) );
?>
<?php while ( $popular->have_posts() ): $popular->the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a> (<?php comments_number( 'Nu stemmen!', '1', '%' ); ?>)</li>
<?php endwhile; ?>
How can I make it happen that instead of showing the posts with the most comments it shows the posts with the highest voted comments on my homepage?
I don’t know if it’s even possible.
To be complete, this is in my functions.php:
<?php
/* Display likes/unlikes */
function aigoo_get_score() {
$comments = get_comments( array('post_id' => get_the_ID(),) );
$likes = array();
$unlikes = array();
foreach( $comments as $comment ) {
if('unlike' == $comment->comment_content ) $unlikes[] = $comment;
else $likes[] = $comment;
}
$likescore = count( $likes );
$unlikescore = count( $unlikes );
$score = count($likes) - count($unlikes);
$totalvotes = count($likes) + count($unlikes);
return compact('likes', 'unlikes', 'likescore', 'unlikescore', 'score', 'totalvotes');
}
?>