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 am working on a Mini Job Site.

i want to give rating to posts manually from admin / editor side

Best rated people will be on top. so visitor'll get better choice.

visitor are not allowed to rate posts

like this

please have a look

how to do this ?

{1} Meta-box uses {2} Custom Field

help me please

share|improve this question
    
do you use some kind of plugin, if so provide link. –  amit Aug 3 '12 at 11:44
    
no Amit .. not using –  Nisha_at_Behance Aug 3 '12 at 11:50
add comment

1 Answer

up vote 2 down vote accepted

Here's something I'd use if I want to do that without using plugins

Create a custom field as rating and provide the value while doing post. Suppose I gave a rating of 6, Now wordpress save it into the database as.

  • meta_key => rating
  • meta_value => 6

Now to show the rating on post I'll use this code into single.php or index.php but make sure to put it within Wordpress loop -

<?php
    //grab the rating value
    $rating = get_post_meta($post->ID, 'rating', true);

    //prints star image
    for ($i=1; $i<=$rating; $i++){
        echo '<img src="LINK-TO-STAR-ICON"/>';
    }

    //prints unstar image
    for ($i=$rating; $i<10; $i++){
        echo '<img src="LINK-TO-UNSTAR-ICON"/>';
    }
?>

The above code will result like this - enter image description here

share|improve this answer
    
If that helped, consider up voting it. –  amit Aug 3 '12 at 13:07
    
Amit, Custom field not working if you can help me i m not very smart in php. $rating = get_post_custom_keys(); foreach ( $rating as $key => $value ) { echo $key . " => " . $value . "i+"; } –  Nisha_at_Behance Aug 3 '12 at 13:47
    
what exactly not working. ? –  amit Aug 3 '12 at 13:49
    
custom field not showing in post section –  Nisha_at_Behance Aug 3 '12 at 13:54
    
My code works great on my site, Why you 're using that other code ? –  amit Aug 3 '12 at 13:59
show 3 more comments

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.