I'm using this PHP to show the comments on my homepage:
Functions.php
function tootsweet_article_total_comments() {
return Comment::where('post', '=', article_id())
->where('status', '=', 'approved')
->count();
}
Posts.php
<?php if (tootsweet_article_total_comments() > 0)
{
echo '<a href="'.article_url().'#comments">';
if (tootsweet_article_total_comments() == 1)
echo ' comment';
else
echo tootsweet_article_total_comments().' comments';
echo '</a>';
}
?>
All is working perfectly, but when a post has 0 comments, no text is shown at all whereas I want it to say '0 comments'. I'm a bit of an amateur with PHP, so is there something I need to amend here?