将以下函数放入主题函数中。php,然后将<?php echo tnc_reactions_count($post->ID); ?>
在你的单曲里。php输出数字。让我知道它是否工作,因为我还没有完全测试它。
function tnc_reactions_count($post_id){
global $wpdb;
$comments_table = $wpdb->prefix.\'comments\';
$commentsmeta_table = $wpdb->prefix.\'commentmeta\';
$get_post_comments = $wpdb->get_results( "SELECT * FROM $comments_table WHERE comment_post_ID=\'$post_id\'", OBJECT );
$funny_total = 0;
$sad_total = 0;
$hate_total = 0;
$good_total = 0;
foreach ($get_post_comments as $key => $value) {
$comment_id = $value->comment_ID;
$query_reaction = $wpdb->get_results( "SELECT * FROM $commentsmeta_table WHERE `comment_id`=\'$comment_id\' AND `meta_key`=\'comments_reactions\'", OBJECT );
foreach ($query_reaction as $key => $value) {
$get_reaction = $value->meta_value;
switch ($get_reaction) {
case \'funny\':
$funny_total += 1;
break;
case \'sad\':
$sad_total += 1;
break;
case \'hate\':
$hate_total += 1;
break;
case \'good\':
$good_total += 1;
break;
}
}
}
$output = \'<h3>Reactions</h3>\';
$output .= \'Funny: \'.$funny_total;
$output .= \'Sad: \'.$sad_total;
$output .= \'Hate: \'.$hate_total;
$output .= \'Good: \'.$good_total;
return $output;
}
谢谢