Support » Plugin: Vote It Up » [Plugin: Vote It Up] "Most Voted Posts" only from certain category

  • How can I edit the code of the “Most Voted Posts” widget to only show posts from a particular category?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Ben Dunkle

    (@empireoflight)

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Vote It Up] "Most Voted Posts" only from certain category’ is closed to new replies.