Jump to content


Photo

Comment counting returns odd number

blog commenting

  • Please log in to reply
4 replies to this topic

#1 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 405 posts
  • 118

  • LocationOttawa, Canada

Posted 18 April 2012 - 09:22 AM

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 :)

#2 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 405 posts
  • 118

  • LocationOttawa, Canada

Posted 18 April 2012 - 09:27 AM

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 :)

#3 Soma

Soma

    Hero Member

  • Moderators
  • 3,217 posts
  • 1764

  • LocationSH, Switzerland

Posted 18 April 2012 - 09:27 AM

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.

@somartist | modules created | support me, flattr my work flattr.com


#4 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 405 posts
  • 118

  • LocationOttawa, Canada

Posted 18 April 2012 - 09:30 AM

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, 18 April 2012 - 09:30 AM.


#5 Soma

Soma

    Hero Member

  • Moderators
  • 3,217 posts
  • 1764

  • LocationSH, Switzerland

Posted 18 April 2012 - 09:34 AM

I just popped in, and it was easy.

Glad I could help you. :)

@somartist | modules created | support me, flattr my work flattr.com






Also tagged with one or more of these keywords: blog, commenting

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users