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/
Thanks!
<?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>
<div class='post-image-inner right'>
img src='".get_bloginfo( 'template_directory' )."/timthumb.php?src=".get_post_meta( $post->ID, 'image_value', true )."&w=225&h=246&zc=1' />
</div>
</div>";
}else{ echo "<div class='post-image'><img src='".get_bloginfo('template_directory')."/timthumb.php?src=".get_post_meta( $post->ID, 'image_value', true )."&w=529&h=253&zc=1' /></div>";
}
}
?>
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 toreturn
it’s value to use it that way:Also –
should be:
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(); ?>