Hi,
I use this code to show the post score which bcworkz made for me:
<?php
$counts = aigoo_get_score();
extract( $counts ); //restores compacted variables
<span>+'.$score.'</span>
?>
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');
}
?>
Now comes the new part of code I just use. 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? (See the first and second code.)
I don't know if it's even possible. Hopefully someone can help me with this.
Problem 2:
I also notice that when I duplicate this code and change the categoryname it lists both only one category even when the category name is different.