运行SQL查询,通过作者在帖子中获得的投票来获取作者。
@邦格在我的第一篇文章中帮了我,并帮助我把这篇文章做得很好,但我提出了这个新问题,因为这是一个单独的问题。
<?php
global $wpdb;
$date2 = date(\'Y-m-d\', strtotime(\'-60 days\'));
$weekly = $wpdb->get_results ( "
SELECT u.display_name as name,
( SELECT
CONCAT_WS(\'.\',
SUM(CASE WHEN p.post_date > \'$date2\' THEN pm.meta_value ELSE 0 END),
SUM(pm.meta_value))
FROM wp_posts p, wp_postmeta pm
WHERE p.post_author = u.ID
AND p.post_status LIKE \'publish\'
AND pm.meta_key = \'epicredvote\'
AND p.ID = pm.post_id ) as votes
FROM wp_users u
ORDER BY votes+0 DESC LIMIT 0,5
" );
foreach ($weekly as $result) {
$name = $result->name;
list( $weekly_vote, $total_vote ) = explode( \'.\', $result->votes ? $result->votes : \'0.0\' );
// do stuff with $name, $weekly_vote, $total_vote ...eg
echo $name, \'<br>\', \' Weekly Karma: \', $weekly_vote, \'<br>\',\' Total Karma: \', $total_vote, \'<br><br><br>\';
}
?>
在做了一些环顾之后,我遇到了一些与此集成时遇到困难的示例代码。
我想有一个指向作者URL的名称链接,并显示作者头像。
类似->
<a href="\' . get_author_posts_url( $author->ID ) . \'">\' . get_the_author_meta( \'user_nicename\' , $author->ID ) . \'
\' . get_avatar( $author->ID , 40 ) . \'
</a> \' Weekly Karma: \', $weekly_vote, \'<br>\',\' Total Karma: \', $total_vote, \'<br><br><br>\';