There is a template for wordpress, which displays the number of comments before the posts with the following code:

<a href="<?php comments_link(); ?>" class="link-comments"><?php comments_number("0 ".__('Comments','theme'), "1 ".__('Comment','theme'), "% ".__('comments','theme')); ?></a> 

How to change it so that at 0 nothing is output at all (now 0 Comments are output accordingly).

* Just starting to understand

  • 2
    replace "0" .__ ('Comments', 'theme') with an empty string "" as an option - kandellak
  • if you replace 'Comments', 'theme' with '', '' then 0 will be displayed, which is not needed - Cola
  • and if "0" .__ ('Comments', 'theme'), 0 then from here "0" - kandellak
  • one
    Here from codex is a more vivid example of using the <? php comments_number ('no responses', 'one response', '% responses') function; ?>. - kandellak

1 answer 1

You can wrap your code as a check for comments:

 <?php if (get_comments_number( $post_id )): ?> <a href="<?php comments_link(); ?>" class="link-comments"><?php comments_number("0 " . __('Comments', 'theme'), "1 " . __('Comment', 'theme'), "% " . __('comments', 'theme')); ?></a> <?php endif ?> 

The get_comments_number () function does not require a parameter if it is executed in a loop, otherwise you need to specify the record id.

Or, as already indicated kandellak:

 <?php comments_number("", "1 " . __('Comment', 'theme'), "% " . __('comments', 'theme')); ?>