Ranking Archive Page

I have set up an archive page that only includes the post title and the voting. Users will be voting on the top domains and can submit these domains through the site using formidable forms. I would like for this page to organize these posts by the highest ranked first.

Again, this is a simple archive page. They users will not even have a link to the actual single page post.

The archive page is: http://youthministryresources.com/toprated/

The code I have is:
'<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="toprated"><div id="topratedvote"><div align="center"><?php wdpv_vote(); ?></div></div><div id="topratedtitle"><p>" title="<?php the_title(); ?>"><?php the_title(); ?></p></div></div>

<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>'

  • Philip John

    Hiya Eric,

    Hmm this is a tricky one..... My first thought is that you can grab the IDs of the highest voted posts by querying the post voting table.

    Then you'd simply pass that list of IDs to the orderby parameter in WP_Query.

    However, looking at that parameter it might not be so simple:
    http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

    Definitely worth a try though!

    Phil

  • Eric G.

    Phil,

    Sorry my querying knowledge is way limited and something I have been researching lately. Can you or someone else provide me some examples of code that would be used? I understand I'm asking a lot, but I think I got pretty creative with this idea and how I'm using the different plugins and would love to see it work as it opens up more possibilities.

    Thanks for any help you can give. In the meantime I will research queries. I just do not want to test it when I wouldn't be sure if the query basics are what are wrong or the testing I am doing. Need the foundations first, then I can work from there.

  • Philip John

    I'm gonna pull Ve in here actually because there is a better way.... I can't see if the plugin uses post_meta or not but if it did, you could do something as simple as;

    <?php
    // grab posts by post count ordered in descending order (most votes first)
    $query = 'meta_key=wpd_votes&orderby=meta_value&order=DESC';
    $queryObject = new WP_Query($query);
    // The Loop...
    ?>

    That would simply require the plugin to update a total votes counter which is stored in a post_meta value and therefore associated with that post in a way WP can understand.

    Phil

  • Eric G.

    Ok, so this is what I have so far. Not working yet, but thought it would help others problem solve.

    The page that is using this is: http://youthministryresources.com/toprated/

    <?php
    // grab posts by post count ordered in descending order (most votes first)
    $query = 'meta_key=wpd_votes&orderby=meta_value&order=DESC';
    $queryObject = new WP_Query($query);
    // The Loop...
    ?>
    		<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    		<div id="toprated"><div id="topratedvote"><div align="center"><?php wdpv_vote(); ?></div></div><div id="topratedtitle"><p><a href="<?php the_title(); ?>" title="<?php the_title(); ?>" target="_blank"><?php the_title(); ?></a></p></div></div> 
    
    		<?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    I assume that the comment "The Loop" means the php should be wrapped around the loop. I am not familiar enough with php to know how to do that though where you take out the calls for php throughout the code.