WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>";
share|improve this question

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)
share|improve this answer
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 ==. – Chip Bennett Jul 17 '11 at 22:02
@Chip Bennett - ha, Yoda casing. good tip! – Milo Jul 18 '11 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(); ?>

share|improve this answer

Your Answer


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.