1

I defined a variable called $thumbs_number.

I did var_dump:

string(52) "2"

and print_r

2

It looks like $thumbs_number is 2 right now. But then I do this:

<?php if ( $thumbs_number == 2 ) : ?>
    <span><?php _e( 'two likes' ); ?></span>
<?php else : ?>
    <span><?php _e( 'likes' ); ?></span>
<?php endif; ?>

I'm still getting 'likes' not 'two likes'

What I'm doing wrong?

EDIT:

here is the variable comming from:

<?php $thumbs_number = wp_gdsr_render_article_thumbs($template_id = 46, $read_only = false, $stars_set = "", $stars_size = 0, $stars_set_ie6 = "", $echo = false); ?
2
  • 1
    string(52) says that it's not only "2". Where does this string come from? Commented Aug 12, 2011 at 13:27
  • The comment above (deceze) hints into the right direction; the string contains more than just the 2, so the comparison must fail. Btw - what kind of strange function call is that? Commented Aug 12, 2011 at 13:55

2 Answers 2

2

http://plugins.svn.wordpress.org/gd-star-rating/tags/1.9.9/code/fn/legacy.php says "@return string html with rendered contents" in the docs. It is probably not just returning the number, or whitespace along with it, but html-tags (you can check this by using 'view source' on the output result. If you just view it in the browser, it will parse the html-tags and you won't see them.)

A simple trim isn't enough. (Besides, php can autoconvert the string with spaces to a number.) Either check for a more appropriate wordpress function that gives it back number you want without html, or use a regexp / substring to extract the number.

Sign up to request clarification or add additional context in comments.

Comments

0
$thumbs_number = trim(wp_gdsr_render_article_thumbs($template_id = 46, $read_only = false, $stars_set = "", $stars_size = 0, $stars_set_ie6 = "", $echo = false));

Trim the whitespace and it should compare correctly.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.