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.

Is it possible to have some sort of rating feature based off of x amount of comments or views?

Example:

Instead of saying 200 views, have it say:

"Hot"

400 views, have it say:

"Very Hot"

something similar to a if else statement

value=200 Echo "hot" if else echo "cold"

share|improve this question
3  
How do you track/count your views? –  bungeshea Jan 7 '13 at 3:46
    
Why are people downvoting this? It is a legitimate question. There are many WordPress plugins to count post views. Do you have any solution for this already working? –  Mateusz Hajdziony Jan 7 '13 at 4:25
1  
@pogoking The downvotes are probably for does not show any research effort. Please tell us next time what you have tried already. Add some code, and you will get upvotes. Anyway, welcome to WordPress Stack Exchange! :) –  toscho Jan 7 '13 at 4:32
    
Thanks pogoking 7 i've asked a couple questions in the past and seems to always be downgraded. I become very hestitant to ever ask anything. I have researched this and seem to always stumble on just comment counters, nothing that ouputs and adds up. –  Splinner Jan 7 '13 at 4:39
    
As @toscho pointed out, you will have to show use some research effort. And this doesn't mean "this plugin doesn't do what I want". It's more like "this is what I've read up, here's my concept". And please keep in mind, that this site is not about plugin recommendations. See the faq. –  kaiser Jan 7 '13 at 7:47
show 1 more comment

1 Answer

I would not take visits into account: To get these numbers you have to connect to an external table, or worse write into the WordPress tables on each request.

Use comments, that is built-in. Here is a sample code that adjusts itself to your comment development:

add_filter( 'the_content', 'wpse_78513_hotness' );

function wpse_78513_hotness( $content )
{
    static $average = FALSE;

    static $global_stats = NULL;

    if ( FALSE === $average )
        $average = round( wp_count_posts()->publish / wp_count_comments()->approved );

    $current_comments = wp_count_comments( get_the_ID() )->approved;

    $hotness = 'lukewarm';

    if ( $current_comments >= ( $average * 1.5 ) )
        $hotness = 'hot';

    if ( $current_comments <= ( $average / 2 ) )
        $hotness = 'cold';

    $stats = "<p class='hotness'>Hotness: $hotness</p>";

    return $stats . $content;
}

It counts posts and comment on the first call and stores these data in an internal static variable to save time on further calls. Then it takes the comment count for the current post and calculates how much it differs from the average.

You can and should extend it. It is a guide, not a complete solution.

share|improve this answer
    
How would i than output it to show those filters or does that do it for both? –  Splinner Jan 7 '13 at 4:36
    
It seems that code takes an input of some sortof rating then ouputs as "lukewarm" etc is this true? –  Splinner Jan 7 '13 at 4:51
1  
+1 for lukewarm :D –  kaiser Jan 7 '13 at 7:48
    
@Splinner No, it doesn’t take any extra input, just the data offered by your installation by default. –  toscho Jan 7 '13 at 11:52
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.