不久前,我使用了该插件,我需要一种列出大多数投票帖子的方法,因此在查看该插件的小部件代码后,我想到了以下功能:
function top_voted($number){
$a = SortVotes();
echo \'<div class="voted">\';
$rows = 0;
//Now does not include deleted posts
$i = 0;
while ($rows < $number)) {
if ($a[0][$i][0] != \'\') {
$postdat = get_post($a[0][$i][0]);
if (!empty($postdat)) {
$rows++;
echo \'<div class="fore">\';
echo \'<div class="votecount" style="width: 1em; color: #555555; font-weight: bold;">\'.$a[1][$i][0].\' </div><div><a href="\'.$postdat->guid.\'" title="\'.$postdat->post_title.\'">\'.$postdat->post_title.\'</a></div>\';
echo \'</div>\';
}
}
if ($i < count($a[0])) {
$i++;
} else {
break; //exit the loop
}
}
echo \'</div>\';
}
用法:
top_voted(5);