Ali
Ali

Reputation: 10453

Can see the value of the variable but can't use it to validate PHP

<?php
function number_of_fb_comments()
{
    return $number = "<fb:comments-count href=" . get_permalink($post->ID) . " ></fb:comments-count>";
}
?>
<?php
function get_fb_comments()
{
    $number = number_of_fb_comments();

    if ($number == 1) {

        echo "<a href =$url#facebook_comments > $number Comment</a></span>";

    } else if ($number > 1) {

        echo "<a href =$url#facebook_comments > $number Comments</a></span>"; 

    } else {

        echo "<a href=$url#facebook_comments>Leave a comment</a> </span>";

    }
} ?>

I'm trying to make a validation of my facebook comments, but I can't seem to use the '$number' to validate it in the if statement, but I can echo the value and see it.

So it will only goes to the 'else' part....

I have made $number as a global variable and after using var_dumb($number)

I'm seeing series of out put on each of the post

 string(104) "0" 
 string(118) "1"
 string(111) "0"

Upvotes: 0

Views: 40

Answers (1)

Ryan
Ryan

Reputation: 778

The $number you're calling returns a string (return $number = "<fb:comments-count href="), which is not 1 or >1 - it appears you'll want to return some different data from your number_of_fb_comments() function.

Upvotes: 1

Related Questions