最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

templates - small problem in the article ()

programmeradmin2浏览0评论

WP 5.4 Theme masonic

I try to show the numer of comments in each article it'as ok (see the picture) but on the next line, itshow ()

I don't know why !?!?


the code in the file template-tags is:

echo '<div class="entry-author vcard author fa fa-user"><a class="url fn n" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></div>';

// Show number of comments
echo '<div>(' . comments_number( '(0) ', '(1)', '(%)' ) . ')</div>';

WP 5.4 Theme masonic

I try to show the numer of comments in each article it'as ok (see the picture) but on the next line, itshow ()

I don't know why !?!?


the code in the file template-tags is:

echo '<div class="entry-author vcard author fa fa-user"><a class="url fn n" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></div>';

// Show number of comments
echo '<div>(' . comments_number( '(0) ', '(1)', '(%)' ) . ')</div>';

Share Improve this question edited Apr 27, 2020 at 7:24 Jacob Peattie 44.2k10 gold badges50 silver badges64 bronze badges asked Apr 27, 2020 at 7:18 pascalnivpascalniv 1
Add a comment  | 

1 Answer 1

Reset to default 0

There's two issues at play here.

First, you've got two sets of parentheses:

           ↓ Here                 ↓ And Here
echo '<div>(' . comments_number( '(0) ', '(1)', '(%)' ) . ')</div>';

You only want one.

Second, you're trying to concatenate a string (.) with a function, comments_number(), that echoes. This results in comments_number() being outut immediately, and then the rest of the string outputting after that. This is where the second () comes from.

To fix the issue, either remove echo and output like this:

comments_number( '<div>(0)</div>div>', '<div>(1)</div>div>', '<div>(%)</div>div>' ) . ');

Or use get_comments_number_text() which returns the same value:

echo '<div>(' . get_comments_number_text( '0', '1', '%' ) . ')</div>';

Note that I've also removed the redundant parentheses.

发布评论

评论列表(0)

  1. 暂无评论