FORUMS CLOSED DUE TO SPAM. YOU STILL CAN ADD POST!

how to display number of comments on the hompage?

Feed 3 posts, 3 voices

Avatar
2 posts

hi guys,

im wondering if there is a way to show the number of comments in the main homepage..

looking at the default installation i can see the following in the home page body..

<p class=“info”>Posted by <?php echo $last_article->author(); ?> on <?php echo $last_article->date(); ?></p>

is there something like $last_article->commentCount(); that can be called???

appreciate any help here :)

thanks in advance!

kj

 
Avatar
1493 posts

Try this:

<?php if($last_article->comment_status != 0): ?>
     — <?php echo $num_comments = comments_count($last_article); ?> comment<?php if ($num_comments != 1) { echo 's'; } ?> 
<?php endif; ?>

If that throws an error, try changing comments_count to commentsCount.

Also, this uses $last_article since that is what you asked about. You’ll notice on the default homepage, that the rest of the articles are simply referenced by $article, so if you copy the code further down the page, don’t forget to make that change.

(There is some documentation on this, but I’m afraid it’s out of date! Must check…)

Let us know how it goes!

 
Avatar
2 posts

wicked! it worked like a charm!

thanks so much dude!! Il be posting up the site when i finish it! woohooo!

:)

 
Avatar
18 posts

Thanks for this, it was just what I was looking for!