"No comment" not display if there is no comment

Hello,

with template exemple : I want not to display "no comment". But I want also, if there are one or more comments, display title "One comment" or "2 comments", etc. as a title.
(for example, the source would be: `

One comment

,

2 comments

` etc.)

I take the code for comments in exemple template. It is:
`<?php $num = getCommentCount(); echo ($num == 0) ? gettext("No comments") : (($num == 1) ? gettext("<strong>One comment") : "$num ".gettext("comments on this album:")); ?>`

I try to put `

...

` only when there are comments and disable "no comment" when there is no comment.
I Write:

`<?php $num = getCommentCount(); echo ($num == 0) ? "" : (($num == 1) ? echo "<h3>" gettext("One comment") : "$num ".gettext("comments on this album:")); ?>`

That don't work.

One idea?

Comments

  • acrylian Administrator, Developer
    `
    <?php $num = getCommentCount();
    if ($num != 0) {
    if($num == 1) {
    <display one comment>
    } else {

    }
    }
    `
    Sometimes the long written version is more clear than the short term...:-)
  • Thank's. I try it (I m'not yet include <h3> at this time)

    `
    <?php $num = getCommentCount();
    if ($num != 0) {
    if($num == 1) {
    gettext("<strong>One comment")
    } else {
    "$num ".gettext("comments on this image:")
    }
    }
    ?>
    `
    but I have message error...
  • acrylian Administrator, Developer
    Of course, you have basic errors in your code. Try this:

    `
    <?php $num = getCommentCount();
    if ($num != 0) {
    if($num == 1) {
    echo gettext("<strong>One comment");
    } else {
    echo "$num ".gettext("comments on this image:");
    }
    }
    ?>
    `
    Please try to learn the basics of php. There are lots of tutorials out there. I hope you will understand that we can't teach those here.
  • yes, basics errors...

    To finish this post, I correct it and include `

    ...

    ` with "One comment" and "xx comments". There is nothing in the code source if there is 0 comments (no h3 balises empty).

    This code is ok:

    `
    <?php $num = getCommentCount();
    if ($num != 0) {
    if($num == 1) {
    echo "<h3>".gettext("One comment")."";
    } else {
    echo "

    $num ".gettext("comments on this image:")."

    ";
    }
    }
    ?>
    `
    Thank you.
  • acrylian Administrator, Developer
    You are welcome (in case I may have sounded a little harsh). Last note, in case translation is important for you. The gettext calls will probably not work correctly since this is not the setup the translation files are made with.
Sign In or Register to comment.