如何更改“评论"上的单数/复数?到“评论"在 Facebook 上的评论数? [英] How do I change the singular/plural on "comment" to "comments" on Facebook's number of comments?

查看:32
本文介绍了如何更改“评论"上的单数/复数?到“评论"在 Facebook 上的评论数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的 Wordpress 博客中的字幕能够计算我帖子中 Facebook 评论的数量.插入 Facebook 代码后

I would like my subtitles in my Wordpress blog to count the number of Facebook comments on my post. After inserting Facebook's code

<span class="comment-count">
   <fb:comments-count href="<?php echo get_permalink($post->ID); ?>">
   </fb:comments-count> comments
</span>

我意识到当我只有 1 条评论时,它会以复数形式打印1 条评论".我需要对代码进行哪些更改才能:

I realise that when I only have 1 comment it prints "1 comments", in plural. What changes in the code do I need to do in order to:

  • 没有评论时打印无评论"
  • 当只有一条评论时,以单数形式打印1条评论"
  • 当有多条评论时以复数形式打印X条评论"

对不起,如果这是一个愚蠢的问题,但我对编码 (PHP)、Wordpress 和 Facebook 工具完全陌生.

Sorry if this is a dumb question but I am completely new to coding (PHP), Wordpress and the Facebook tools.

推荐答案

单独使用 fb:comments-count 标签是不行的.您需要做的是首先将注释的数量放入 PHP 变量中,然后根据该变量的值打印正确的短语.您可以使用 PHP SDKFQLGraph API.然后,打印您想要的内容的一种方法:

Using the fb:comments-count tag by itself, you can't. What you need to do is get the number of comments into a PHP variable first and then print the correct phrase depending on the value of that variable. You can retrieve the number of comments using the PHP SDK, FQL, or the Graph API. Then, one way to print what you want:

 <?php
 $comments = getCommentCountUsingGraphAPI();

 if ($comments == 0) {
    echo "No comments";
 } elseif ($comments == 1) {
    echo "1 comment";
 } else {
    echo "$comments comments";
 }
 ?>

但是妥协要容易得多,只需稍微修改您的演示文稿即可完全避免复数问题:

But it's a lot easier to compromise and just modify your presentation a little to avoid the pluralization issue entirely:

 <span class="comment-count">
      Comments: <fb:comments-count href="<?php echo get_permalink($post->ID); ?>"></fb:comments-count>
 </span>

或者:

 <span class="comment-count" title="Comments">
      <fb:comments-count href="<?php echo get_permalink($post->ID); ?>"></fb:comments-count>
 </span>

这篇关于如何更改“评论"上的单数/复数?到“评论"在 Facebook 上的评论数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆