WordPress.org

Ready to get started?Download WordPress

Forums

WP Voting
[resolved] [closed] Post Ranking (34 posts)

  1. vusisindane
    Member
    Posted 2 years ago #

    Hi there, I'm trying to get the 'rank' of a post according to the number of votes it has. e.g. let's say I have 3 posts.
    POSTA = 10 votes
    POSTB = 20 votes
    POSTC = 30 votes.

    Then POSTC should be ranked #1, POSTB #2 etc. I want to write a function that gets that rank. Is there an easier way to get this done? or should I just go ahead and hack the plugin?

    http://wordpress.org/extend/plugins/wp-voting/

  2. tristanmin
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    I am going to do as a widget or shortcode. It will be included in next release.

    Cheers!

  3. razzgpe
    Member
    Posted 2 years ago #

    Hey tristanmin.

    When do you will release the new version with ranking?
    I need it for a project for my university.

    Greetings from Germany!
    Alex

  4. vusisindane
    Member
    Posted 2 years ago #

    I've actually implemented it. If you want I can give you the code...
    please see http://www.be1idea.org/ideas/the-joy-of-physics/

  5. razzgpe
    Member
    Posted 2 years ago #

    Wow! That would be pretty cool!
    It looks very nice!

    My Emailadress:
    elecsander[at]gmail.com

    Thank you very much!
    Greetings from Germany!
    Alex

  6. vusisindane
    Member
    Posted 2 years ago #

    What I will do is build an independent plugin that hooks into this one so that we can allow the original author to continue working on his plugin without disturbing the process.

    Please give me until Saturday to do this for you...

    P.S
    Greetings from South Africa :)

  7. razzgpe
    Member
    Posted 2 years ago #

    Wow! That is so cool! With a rank the WP Vote Plugin is perfect!
    Thank you very much for your engagement!

    I will post my project with both plugins, when I finsh it.

    Best regards from Germany! :-)

  8. razzgpe
    Member
    Posted 2 years ago #

    Hey!

    Do you have the solution?
    It would be nice, when you could give me the code.
    I just need the code to paste it in the loop.

    I have two loops.

    The normal loop: http://goo.gl/WjtHF
    The random loop: http://goo.gl/dibKA

    And now I need the code for "The ranking loop" with a ranking of the votes of WP Voting.

    When you or tristanmin could help me, then it would be pretty cool!!

    Greetings from Germany!

  9. vusisindane
    Member
    Posted 2 years ago #

    Sorry, my weekend turned out to be a disaster. I'm working on it as we speak. Will send it through.

  10. vusisindane
    Member
    Posted 2 years ago #

    things have been super hectic. so please accept this code rather than the entire widget. you can look up on wordpress codex on how to make a widget

    function b1_get_post_rank($post)
    {
    	global $wpdb;
    
    	$total_posts = $wpdb->get_var('SELECT COUNT( DISTINCT vote_count)
    					   	FROM ' . $wpdb->prefix . 'wpv_voting');
    
    	$total_smaller = $wpdb->get_var('SELECT COUNT( DISTINCT vote_count )
    					   	FROM ' . $wpdb->prefix . 'wpv_voting
    						WHERE vote_count < (SELECT vote_count
    											FROM ' . $wpdb->prefix . 'wpv_voting
    											WHERE post_id = ' . $post->ID . ')');
    
    	$rank = $total_posts - $total_smaller;
    
    	return $rank;
    }
  11. vusisindane
    Member
    Posted 2 years ago #

    Feel free to improve it and let me know (and let the plugin author know) if you do.

  12. razzgpe
    Member
    Posted 2 years ago #

    Thank you very much!
    How can I get the ranking?

    <?php b1_get_post_rank($post) ?> doesn't work.

    I also tried to get the rank into this loop:

    <?php
    /*
    Template Name: Ranking
    */
    ?>
    <?php get_header(); ?>
        <?php
        if (is_page('ranking')) {
        b1_get_post_rank($post);
        include(TEMPLATEPATH."/index.php");
        } else { ?>
    <!--Page Content-->
        <?php } ?>
    <?php get_footer(); ?>

    But it doesn't work!

    Thank you very much for your code-solution.
    I hope, you can help me again! :-/

    Best regards,
    Razz

  13. vusisindane
    Member
    Posted 2 years ago #

    1. you must paste that code I gave you in your functions.php
    2. in your template (or in your loop) you can call that function i.e.

    <?php echo b1_get_post_rank($post) ?>

    It should return an int (number), that number is the rank of the post. One thing though, just make sure the $post is actually a valid variable. if $post is null, then it won't work. one way to get the post is to use <?php global $post; ?> (provided wordpress has declared it)

  14. tristanmin
    Member
    Plugin Author

    Posted 2 years ago #

    Oh guys! I didn't know that you guys are implementing top voted feature. I got a lot of work to do at my primary job. So I couldn't check this blog post lately. If I knew it early, that make me a lot easier to develop the top voted widget. Anyway, I've finished the top voted widget and which is included in version 1.7. Please let me know if you need my help.

    Thanks for all the contributors and supporters.

    Cheers!

  15. vusisindane
    Member
    Posted 2 years ago #

    Thanks.
    Will definitely check it out.

  16. razzgpe
    Member
    Posted 2 years ago #

    Hey! I couldn't get it to work! :-D
    With the solution of vusisindane it works, that I get a number of the rank.
    But I'm just a PHP rookie and I can't make a loop-ranking site with all posts in a ranking.

    I'm working on a project-site for my university and need a site, where I can sort the projects ( = posts/blogarticles) by the ranking

    http://goo.gl/a8JeO

    So I'm happy, when you release 1.7.
    When is the release-date?

    Greetings from Germany!

  17. razzgpe
    Member
    Posted 2 years ago #

    Yeah. It's online. I will check this out and report.

  18. razzgpe
    Member
    Posted 2 years ago #

    Ok, I gave up.

    How can I rank the posts in a loop?
    Is there a solution?

    I tried crazy things like <?php add_action( 'Wpv_Top_Voted_Widget' );?>
    but it's not logical and it doesn't work.

    Can somebody help me?

    This is the project site: http://goo.gl/ho8XF
    This is the project site with random sort: http://goo.gl/3mUep
    And now it would be pretty cool to have a site with rank: http://goo.gl/H7iHX

    Is there a solution to implement the rank like:

    <?php
    /*
    Template Name: Ranking
    */
    ?>
    <?php get_header(); ?>
    
    <?php
        if (is_page('ranking')) {
    		global $post;
    		$query_posts = wpvtopvoted($post);
    		query_posts();
        	include(TEMPLATEPATH."/index.php");
        } else { ?>
    <!--Inhalt-->
    
    <?php } ?>
    <?php get_footer(); ?>
  19. razzgpe
    Member
    Posted 2 years ago #

    Hey.

    When do you release the new version with the feature "Top voted posts list shortcode"?

    I still need a ranking without a widget. I need it in the content.

    Best regards.
    Razz

  20. wper2012
    Member
    Posted 2 years ago #

    Hi,

    here is my solution:

    [Code moderated as per the Forum Rules. Please use the pastebin]

  21. jcl0009
    Member
    Posted 2 years ago #

    Hey,

    when i place the short code [wpvoting] onto a page, even if i place it after a few words, it shows up on the website before everything how do i fix this?

  22. razzgpe
    Member
    Posted 2 years ago #

    Hey wper2012,

    can you repost your code right?
    I can't see your solution!

    Thanks!
    Best regards from Germany,
    Razz!

  23. razzgpe
    Member
    Posted 2 years ago #

    @vusisindane:

    Can you post the code, how did you made the "TOP IDEAS" ranking?
    How did you made this loop?

    Best regards from Germany,
    Razz!

  24. wper2012
    Member
    Posted 2 years ago #

  25. razzgpe
    Member
    Posted 2 years ago #

    wper2012:

    It works!!! Thank you! Very cool!

    Now I try to get this in the query_post.
    Because I want to put a filter-selection in the sidebar.
    One seletion is to sort all posts "random" and the other should be the "ranking".
    But I can't get it since hours.

    When it works, I will update here.

    Do you have any ideas?

    Best regards,
    Razz!

  26. razzgpe
    Member
    Posted 2 years ago #

    The very easy way would be something like:

    query_posts( 'orderby=result' );

    I know, it can't work. But is there any easy solution, like this?

  27. razzgpe
    Member
    Posted 2 years ago #

    @Tristan:
    Is here no support?

    Is it possible to get the top voted results in the query_posts?
    My problem is this:

    My query_posts looks like this:
    http://goo.gl/bjoWH

    But your top voted list looks like this:
    http://goo.gl/klVfW

    I have been asking here for this problem for 6 months now.
    Please look at all my posts.
    Is there a solution?

    Yes or No?

    Thank you,
    best regards! ;-)
    RaZz!

  28. tristanmin
    Member
    Plugin Author

    Posted 2 years ago #

    @razzgpe

    Please use below code to alter query_posts.

    add_filter('posts_orderby', 'edit_posts_orderby');
    add_filter('posts_join_paged','edit_posts_join_paged');
    
    function edit_posts_join_paged($join_paged_statement) {
        global $wpdb;
        $join_paged_statement = "LEFT JOIN ".$wpdb->prefix."wpv_voting ON ".$wpdb->prefix."wpv_voting.post_id = $wpdb->posts.ID";
        return $join_paged_statement;
    }
    
    function edit_posts_orderby($orderby_statement) {
        global $wpdb;
        $orderby_statement = "(".$wpdb->prefix."wpv_voting.vote_count) DESC";
        return $orderby_statement;
    }

    Wrap those two filters with conditional statement not to effect every query_posts. Something like this if(!is_admin() && is_page('Home')){ //two filters }

    Cheers! :)

  29. razzgpe
    Member
    Posted 2 years ago #

    IT WORKS!
    Oh, that is soo great!

    Thank you very much!

    Best regards! :-)

  30. tristanmin
    Member
    Plugin Author

    Posted 2 years ago #

    Great! happy to hear that :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags