WordPress.org

Forums

Vote It Up
"Most Voted Posts" only from certain category (3 posts)

  1. nvolpe
    Member
    Posted 4 years ago #

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

  2. Ben Dunkle
    Member
    Posted 4 years ago #

    I'd like to know this as well.

  3. Robert
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags