WordPress.org

Ready to get started?Download WordPress

Forums

Comment Author Ranks - Close to being done, need help! (10 posts)

  1. Fernando Yet To Die
    Member
    Posted 3 years ago #

    Hi, I am trying to do the following idea:

    Every Comment Poster (Only Comment poster), will have a LEVEL from 1 to 50 based on how many COMMENTs they have posted since registration. As well as show the current total of comment posts.

    I managed to get far with this!

    Guests have a ELSE { } call, that gives then all a Level 1.

    However, my problem is finding the COMMENT POSTER ID.

    I downloaded a Plugin called: Bainternet User Ranks (http://en.bainternet.info/2011/wordpress-user-ranking) that does this for POST AUTHORS, and is supposed to collect information from ALL registered Users with an ID, collecting their total of Posts and Comments.

    However, I cant manage to find a way to collect the ID of all the Commment Authors from a Particular Post.

    Here comes your help! Please, I lie not when saying I lost over 20 hours trying already.

    Here is the code I am using right now:

    <?php
    $user = "";
    if ($comment->user_id) {
    $user=get_userdata($comment->user_id);
    
    	$baur_plugin = new baur_Plugin();
    	$user_rank = $baur_plugin->ba_get_user_points($user->ID);
    	echo "". $user_rank['title'];
    	echo "". $user_rank['points'];
    	echo $user->ID;
    
    }
    else {
    	echo "1";
    }
    
    ?>

    If you look at echo user->ID, that code DOES return ID 1 and ID 2 perfectly to the respective Comment Posters on my page, but, when addressed for this plugin, the Comment Loop ends up calculating wrong Ranks.... It should show Level 11 for ID 2, and Level 50 for ID 1, but it shows level 2, and level 22, then shows level 661... Its strangely broken.

    Link to the Page:
    http://demolishman.com/diablo/about-us/feedback/

    Just look at it.. First its Level 1 (Blue post is me). Then its Level 661?

    I configured ranks like this:
    Rank 1 = Level 1 = 1 post.
    rank 5 = Level 5 = 50 posts.
    Rank 50 = Level 50 = 500 posts.

    I have over 500 posts, so I should ALWAYS show as level 50.

    Help?

  2. Fernando Yet To Die
    Member
    Posted 3 years ago #

    Oh let me add. The Comment Total is already showing as Experience in that page. But that is because I am using a different code from the Plugin mentioned.

    The code to show the total of Posts made by Guests or Registered, based on their NAME, is the following (and works):

    a function for function.php

    function commentCount() {
        global $wpdb;
        $count = $wpdb->get_var('SELECT COUNT(comment_ID) FROM ' . $wpdb->comments. ' WHERE comment_author = "' . get_comment_author() . '"');
        echo $count . '';
    }

    Where I changed from email, for a search based on comment author name, as my guests use the same name with bogus emails.

    AND

    <?php commentCount(); ?>

    This goes in any page, to show the content of each individual comment poster. Works perfect! I always have 700+ Posts, and guests are continuously increasing their posts as they post comments... They don't even need to register.

    :)

  3. Bainternet
    Member
    Posted 3 years ago #

    @DemolishMan : you made a big salad mixing everything up.

    if i under stand correctly what you are trying to achieve then you need to understand that it counts comments as well as posts (posting a comment is called a comment).

    So try this:

    First configure the plugin to count only comments (it looks like its counting both comments and posts).

    then in your code change your conditional check from:
    if ($comment->user_id) {

    to

    if ($comment->user_id > 0) {

    since $comment->user_id is always set to 0 (zero) if there is no user id.

    and as for setting up the ranks, its not the number of posts or comments its the number of points.

    so its actually
    Rank 1 => Level 1 -> over 1 point
    Rank 5 => Level 5 -> over 50 point
    Rank 50 => Level 50 -> over 500 point

  4. Fernando Yet To Die
    Member
    Posted 3 years ago #

    Thanks for looking into! I greatly appreciate!
    I only know the basics of Php. Am trying your advice!

  5. Fernando Yet To Die
    Member
    Posted 3 years ago #

    It didnt work, the first comment I done, shows nothing (echos no value).

    The second post, shows the title called Two, but that is for having only 2 points. I should be rank called FIVE, for having over 500 points.

    (Ps I renamed the ranks to words, for easy understanding of whats wrong).

    <?php
    $user = "";
    if ($comment->user_id > 0) {
    $user=get_userdata($comment->user_id);
    
    	$baur_plugin = new baur_Plugin();
    	$user_rank = $baur_plugin->ba_get_user_points($user->ID);
    	echo "". $user_rank['title'];
    
    }
    else {
    	echo "NA";
    }
    
    ?>

    This is the new code. This code is inside the loop inside the comments.php

  6. Fernando Yet To Die
    Member
    Posted 3 years ago #

    Ranks are as follows

    one - 1 points
    two - 50 points
    tree - 100 points

    but when echoing a rank title, I get the number 2 (actual number) instead of the rank "tree".

    <?php
    if ($comment->user_id > 0) {
    $user=get_userdata($comment->user_id);
    
    	$baur_plugin = new baur_Plugin();
    	$user_rank = $baur_plugin->ba_get_user_points($comment->user_id);
    	echo $user_rank['title'];
    
    }
    else {
    	echo "NA";
    }
    
    ?>

    Also tried the above, no different results.

    1- First comment comes empty.
    2- Second comment does not show rank title, instead show a random number.

  7. Bainternet
    Member
    Posted 3 years ago #

    I'm confused , you say

    the first comment I done, shows nothing (echos no value).
    The second post, shows the title called Two,...

    are you counting comments or posts?
    also can you send a screenshot of your options panel?

    and maybe a pastie or pastbin of your whole code?

    i'll be able to help you even more.

  8. Fernando Yet To Die
    Member
    Posted 3 years ago #

    I am getting somewhere..

    I used this code to see what Im getting and this is waht I got:

    <?php
    	echo "". $user_rank['title'];
    	echo "". $user_rank['points'];
    ?>

    Post by Admin = title is 1 and pounts is 1.
    Post by subscriber = title is 5 and points is 5.

    So, Title and Points are the same number in that variable... So, I dont know what I done, but the plugin seems to have broken.

    I don't know how to fix this, I tried everything.

    :P

  9. Fernando Yet To Die
    Member
    Posted 3 years ago #

    Thanks for the help!

    It finally works! I re-installed the newly downloaded plugin, and got to retrieve the Rank and Points.

    Thanks Bainternet.

  10. Bainternet
    Member
    Posted 3 years ago #

    Glad it worked out for you!

Topic Closed

This topic has been closed to new replies.

About this Topic