Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the Vote it up plugin.

Is there a way of placing the two most voted posts at the top? (Like in Youtube)?

I'm not very sure if this is hard or easy to accomplish.

EDIT:

Someone posted a method in the Wordpress forums here, but Mike Schindel said:

This example is absolutely AWFUL. It may work but it's far more code than you needs and may break on a future version of WordPress.

I've been playing with Wordpress for a while but Im still a PHP beginner.

Is there a way of fixing that code posted in the Wordpress forums? Or a better method?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

a while back i used that plugin and i needed a way to list most voted posts so after looking at the plugin's widget code and i came up with this function:

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>';
}

Usage:

top_voted(5);
share|improve this answer
    
So the first part goes to functions.php and the usage part: top_voted(5); goes inside The Loop? or all that code (the first part and the usage part) goes in a template file? –  janoChen Feb 25 '11 at 19:44
1  
i cant remeber but you can try to add the function to the functions.php and the top_voted(5); replaces the loop, so you dont need the loop at all. –  Bainternet Feb 25 '11 at 19:58
    
Yeah I found that code in votingfunctions.php. Thanks! –  janoChen Feb 25 '11 at 20:02
add comment

I believe it would be using postmeta to save votes. I would do that by doing a query_post order by that meta value and get two posts & save their ID in an array and then again use query_posts with post__not_in to not to include those posts in the remaining loop

share|improve this answer
    
it uses its own tables and not postmeta. –  Bainternet Feb 25 '11 at 19:42
    
Alrite, then with your solution, he can save IDs and exclude them in the regular loop. –  Ashfame Feb 25 '11 at 19:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.