How can I edit the code of the "Most Voted Posts" widget to only show posts from a particular category?
How can I edit the code of the "Most Voted Posts" widget to only show posts from a particular category?
I'd like to know this as well.
Disclaimer: I haven't tried this, so I don't know if it works, but you could try something similar to below (changes in bold)
<?php
//Displays the widget
function MostVotedAllTime_Widget() {
$a = SortVotes();
//Before
?>
<div class="votewidget">
<div class="title">Most Voted</div>
<?php
$rows = 0;
//Now does not include deleted posts
$i = 0;
while ($rows < get_option('voteiu_widgetcount')) {
if(is_category('Category ID or Slug or Name')) {
if ($a[0][$i][0] != '') {
$postdat = get_post($a[0][$i][0]);
if (!empty($postdat)) {
$rows++;
if (round($rows / 2) == ($rows / 2)) {
echo '<div class="fore">';
} else {
echo '<div class="back">';
}
echo '<div class="votecount">'.$a[1][$i][0].' '.Pluralize($a[1][$i][0], 'votes', 'vote').' </div><div>guid.'" title="'.$postdat->post_title.'">'.$postdat->post_title.'</div>';
echo '</div>';
}
}
if ($i < count($a[0])) {
$i++;
} else {
break; //exit the loop
}
}
}
//End
?>
Note that you'll want to replace is_category('Category ID or Slug or Name') with the ID, Slug, or Name you want to use.
This topic has been closed to new replies.