Jump to content

Comment counting returns odd number


alan
 Share

Recommended Posts

I have this code testing if a page (blog post page) has one or more comments associated with it:

if($entry->comment.count > 0) {
   $out .= "This post has earned ";
   $commentCount = $entry->comment.count;
   $out .= (int)$commentCount;
   $out .= " comments so far.";
}

The test works fine, but the number of comments is returning something like an ID (I guess) rather than the number of comments.

For example two pages have one comment each and for one it reports:

This post has earned 8 comments so far.

and on the other:

This post has earned 22 comments so far.

I am pretty sure this a PHP-lite-weight issue between the chair and the keyboard. If you're less PHP lite-weight than me and care to comment on what I might need to do, I would be most grateful :)

Link to comment
Share on other sites

Self-solve-time:

Always the same, I'm getting closer to solving now I've posted.

Removing the (int) shows for a post with two comments I get "8|23" so it's clearly the ID of the actual comment. Will experiment more :)

Link to comment
Share on other sites

Try this

count($entry->comment)

or maybe this will work too

$entry->comment->count();

$entry->comment.count definately doesn't, and returns the toString method of the object which is the id's comma separated I would guess.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Soma you are a lightening-powered super-fast uber-coder. Thank you! Will try and report back.

count($entry->comment)

...solved it. THANKS Soma :D

Edited by alan
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...