I'm trying to insert a php code for a post-rating on wordpress. It used to work out of the echo normally and in-place. Now, using this code, instead of the rating showing up after "User Rating:" it renders completely out of the 'anime-info' div and show up above it.

The code is " . the_ratings() . " The full code should be: but " . if(function_exists('the_ratings')) { the_ratings() } . " didn't work so I had to change it.

Here's the full code. Basically, if the category ID assigned to the current post is 4, it shows this text and an image. If it's not, it renders only a image.

Any suggestions?

This is the plugin I'm using http://wordpress.org/extend/plugins/wp-postratings/


    <?php foreach((get_the_category()) as $category)
            { if($category->cat_ID = 4){ echo "<div class='anime-info'>
                    <div class='anime-inf left'>
                    <b>Anime Title:</b> ".get_post_meta( $post->ID, 'anime_title', true )."<br />
                    <b>Creator:</b> ".get_post_meta( $post->ID, 'anime_creator', true )."<br />
                    <b>Genres:</b> ".the_tags()." <br />
                    <b>Studio:</b> ".get_post_meta( $post->ID, 'anime_studio', true )."<br />
                    <b>First aired at:</b> ".get_post_meta( $post->ID, 'anime_firstaired', true )."<br />
                    <b># of Episodes:</b> ".get_post_meta( $post->ID, 'anime_episodes', true )."<br />
                    <b>Official Website:</b> ".get_post_meta( $post->ID, 'anime_website', true )."<br />
                    <b>Anime ii Rating:</b> ".get_post_meta( $post->ID, 'anime_revrating', true )."<br /> <br />
                    <b>User Rating:</b>" .  the_ratings() . "
                    <div class='post-image-inner right'>
                       img src='".get_bloginfo( 'template_directory' )."/timthumb.php?src=".get_post_meta( $post->ID, 'image_value', true )."&amp;w=225&amp;h=246&amp;zc=1' />
                }else{ echo "<div class='post-image'><img src='".get_bloginfo('template_directory')."/timthumb.php?src=".get_post_meta( $post->ID, 'image_value', true )."&amp;w=529&amp;h=253&amp;zc=1' /></div>";

2 Answers 2


It's because you're echoing a function that itself echoes a value. The function has a display parameter that you have to set to false if you want it to return it's value to use it that way:

function the_ratings($start_tag = 'div', $custom_id = 0, $display = true)

Also -

if($category->cat_ID = 4)

should be:

if($category->cat_ID == 4)
  • 1
    To avoid this: if ( $category->cat_ID = 4 ), I would strongly recommend getting in the habit of "Yoda" casing your conditionals, i.e.: if ( 4 == $category->cat_ID ), which will return an error if = is mistakenly used in place of ==. Jul 17, 2011 at 22:02
  • @Chip Bennett - ha, Yoda casing. good tip!
    – Milo
    Jul 18, 2011 at 2:11

Just the_rating() will work.

Without looking at your generated page, not sure if it's styling problem. Make sure that this foreach code block is placed within <?php while (have_posts()) : the_post(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.