无法在我的 WordPress 驱动的博客上工作

发布于 2024-11-06 10:58:43 字数 290 浏览 1 评论 0原文

我在 WordPress 上使用 Facebook 评论插件,评论框工作正常,但我想访问索引页面和单个页面上的计数。在页面上,Facebook Javascript 被加载到页面上。

这是我使用的代码: />comments

但它不计算 FB 评论。

有没有一个简单的代码可以让我检索评论数?

谢谢,

I am using the Facebook comments plugin on WordPress and the comments box is working fine but I want to access the number of counts on the index page and on single pages. On the pages, the Facebook Javascript is loaded on the pages.

Here's the code I used:
<fb:comments-count href=<?php echo get_permalink() ?>/></fb:comments-count> comments

But it doesn't count the FB comments.

Is there a simple code that let me retrieve the number of comment counts?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

枫以 2024-11-13 10:58:43

将此函数包含在您的模板文件中的某个位置:

function fb_comment_count() {

    global $post;
    $url = get_permalink($post->ID);

    $filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url);
    $json = json_decode($filecontent);
    $count = $json->$url->comments;
    if ($count == 0 || !isset($count)) {
        $count = 0;
    }
    echo $count;
}

在您的主页或任何地方像这样使用它

<a href="<?php the_permalink() ?>"><?php fb_comment_count() ?></a>

有同样的问题,该函数对我有用...如果您收到错误...尝试阅读这个

Include this function somewhere in your template file :

function fb_comment_count() {

    global $post;
    $url = get_permalink($post->ID);

    $filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url);
    $json = json_decode($filecontent);
    $count = $json->$url->comments;
    if ($count == 0 || !isset($count)) {
        $count = 0;
    }
    echo $count;
}

use it like this in your homepage or wherever

<a href="<?php the_permalink() ?>"><?php fb_comment_count() ?></a>

Had the same problem, that function worked for me... if you get an error... try reading this.

梦回旧景 2024-11-13 10:58:43

这些评论通常不会出现在这里:

graph.facebook.com/?ids = [your url]

相反,它们会很好地出现在

graph.facebook.com/comments/?ids = [your url]

因此最终解决方案的价值中。

The comments often don't appear here :

graph.facebook.com/?ids = [your url]

Instead they appear well in

graph.facebook.com/comments/?ids = [your url]

Hence the value of the final solution.

旧人哭 2024-11-13 10:58:43

ifennec 的回答似乎很好,但实际上不起作用(facebook 可能改变了一些东西,现在只返回分享数量)。

您可以尝试获取所有评论:

    $filecontent = file_get_contents(
        'https://graph.facebook.com/comments/?ids=' . $url);

并计算所有评论:

    $json = json_decode($filecontent);
    $content = $json->$url;
    $count = count($content->data);

    if (!isset($count) || $count == 0) {
       $count = 0;
    }
    echo $count;

这只是一个修复程序,直到 facebook 决定阅读有关 fb:comments-count 的常见问题解答,并发现它不起作用:) (http://developers.facebook.com/文档/参考/插件/评论/是的,很棒的评论)。

顺便说一句,我在 Drupal 7 中应用了该功能:) 非常感谢 ifennec,你给我指明了方向。

Answer by ifennec seems fine, but actually is not working (facebook maybe changed something and now is only returning the number of shares).

You could try to get all the comments:

    $filecontent = file_get_contents(
        'https://graph.facebook.com/comments/?ids=' . $url);

And count all:

    $json = json_decode($filecontent);
    $content = $json->$url;
    $count = count($content->data);

    if (!isset($count) || $count == 0) {
       $count = 0;
    }
    echo $count;

This is just a fix until facebook decides to read the FAQ about fb:comments-count, and discovers it's not working :) (http://developers.facebook.com/docs/reference/plugins/comments/ yeah, awesome comments).

By the way, I applied the function in Drupal 7 :) Thank you very much ifennec, you showed me the way.

纵山崖 2024-11-13 10:58:43

这对我有用:

function fb_comment_count() {
  global $post;
  $url = get_permalink($post->ID);
  $filecontent = file_get_contents('https://graph.facebook.com/comments/?ids=' . $url);
  $json = json_decode($filecontent);
  echo(count($json->$url->comments->data));
}

This works for me :

function fb_comment_count() {
  global $post;
  $url = get_permalink($post->ID);
  $filecontent = file_get_contents('https://graph.facebook.com/comments/?ids=' . $url);
  $json = json_decode($filecontent);
  echo(count($json->$url->comments->data));
}
美胚控场 2024-11-13 10:58:43

这已解决。

<p><span class="cmt"><fb:comments-count href=<?php the_permalink(); ?>></fb:comments-count></span> Comments</p>

问题是在我的例子中我使用的是“url”而不是“href”属性。

This is resolved.

<p><span class="cmt"><fb:comments-count href=<?php the_permalink(); ?>></fb:comments-count></span> Comments</p>

The problem was that I was using 'url' than a 'href' attribute in my case.

浅笑依然 2024-11-13 10:58:43

只需将此函数放入 functions.php 中,并将帖子网址传递给 function fb_comment_count 无论您在主题文件中调用它

function fb_comment_count($url) {
$filecontent    = file_get_contents('https://graph.facebook.com/comments/?ids=' . $url);
$json           = json_decode($filecontent);
$content        = $json->$url;

echo count($content->comments->data);

}

Just put this function in functions.php and pass the post url to function fb_comment_count wherever you call it on your theme files

function fb_comment_count($url) {
$filecontent    = file_get_contents('https://graph.facebook.com/comments/?ids=' . $url);
$json           = json_decode($filecontent);
$content        = $json->$url;

echo count($content->comments->data);

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文