Php 如何用注释累积计数替换本机注释计数 我想做什么

Php 如何用注释累积计数替换本机注释计数 我想做什么,php,wordpress,function,plugins,filter,Php,Wordpress,Function,Plugins,Filter,我正在使用一个名为Comments Evolved的插件,该插件聚合来自Faceook、G+和WordPress native的选项卡式评论 我试图用插件聚合计数中的数字替换本机的注释\u编号编号 问题 我想通过functions.php来实现这一点,但我遇到了麻烦,因为它似乎只是在计算Facebook的评论数。我怀疑我的过滤器不起作用,因此它只能拉WordPress native会拉的东西 我试过的 目前我正在使用此过滤器: // Replace native comment count wi

我正在使用一个名为Comments Evolved的插件,该插件聚合来自Faceook、G+和WordPress native的选项卡式评论

我试图用插件聚合计数中的数字替换本机的
注释\u编号
编号

问题 我想通过functions.php来实现这一点,但我遇到了麻烦,因为它似乎只是在计算Facebook的评论数。我怀疑我的过滤器不起作用,因此它只能拉WordPress native会拉的东西

我试过的 目前我正在使用此过滤器:

// Replace native comment count with Comments Evolved comment in native comments_number function
function comments_evolved_number() {
    $number = comments_evolved_get_total_count();
}
apply_filters('comments_number', 'comments_evolved_number');
但它似乎没有发挥作用,因为它只显示Facebook标签上的评论数量

在我的index.php中,我使用这个来获取注释:

        <?php comments_number( 'Say somethin\'!', '1 comment', '% comments' ) ?>
…但在测试中,它似乎没有获得Facebook的评论数量,尽管它收集并汇总了所有其他的评论:

注释演化构造
注释\u演化\u获取\u总数\u计数()
如下所示:

function comments_evolved_get_total_count() {
  $total_count = 0;

  $wordpress_count = comments_evolved_get_wordpress_count();
  //$wordpress_count = get_comments_number();

  $gplus_count = comments_evolved_get_gplus_count();
  $trackback_count = comments_evolved_get_trackback_count();
  $facebook_count = comments_evolved_get_facebook_count();
  $disqus_count = comments_evolved_get_disqus_count();

  $total_count = $total_count + $wordpress_count + $gplus_count + $trackback_count + $facebook_count + $disqus_count;
  return $total_count;
}
//add_filter('get_comments_number', 'comments_evolved_get_total_count', 4269);
function comments_evolved_get_facebook_count($url = "") {
  if(empty($url)){ $url = get_permalink(); }
  $link = 'https://graph.facebook.com/?ids=' . urlencode($url);
  $link_body = wp_remote_retrieve_body(wp_remote_get($link));
  $json = json_decode($link_body);
  return $json->$url->comments;
}
Facebook
comments\u developed\u get\u Facebook\u count()
的结构如下:

function comments_evolved_get_total_count() {
  $total_count = 0;

  $wordpress_count = comments_evolved_get_wordpress_count();
  //$wordpress_count = get_comments_number();

  $gplus_count = comments_evolved_get_gplus_count();
  $trackback_count = comments_evolved_get_trackback_count();
  $facebook_count = comments_evolved_get_facebook_count();
  $disqus_count = comments_evolved_get_disqus_count();

  $total_count = $total_count + $wordpress_count + $gplus_count + $trackback_count + $facebook_count + $disqus_count;
  return $total_count;
}
//add_filter('get_comments_number', 'comments_evolved_get_total_count', 4269);
function comments_evolved_get_facebook_count($url = "") {
  if(empty($url)){ $url = get_permalink(); }
  $link = 'https://graph.facebook.com/?ids=' . urlencode($url);
  $link_body = wp_remote_retrieve_body(wp_remote_get($link));
  $json = json_decode($link_body);
  return $json->$url->comments;
}
我没有发现任何错误,在其他地方,它得出了正确的Facebook计数(我想——不确定)

什么工作正常,但似乎效率不高/不令人满意 …虽然我不太清楚为什么

我这样做是因为(a)我发现在应用过滤器之前插件中的某些东西会干扰聚合计数,(b)因为我认为优先级可能是个问题

更新2 实际上,我已经在两个不同的网站上尝试了上述两种方法。在1个站点上,任何一种方法都可以完美地工作

在站点2上,它未能将Facebook的数量拉到整个总数中。有什么想法吗?

这似乎可行:

function wpse_comments_evolved_number( $count ) 
{
    // Override the comment count
    if( function_exists( 'comments_evolved_get_total_count' ) )
        $count = comments_evolved_get_total_count();

    // We must then return the value:
    return $count;
}
add_filter( 'get_comments_number', 'wpse_comments_evolved_number');
function wpse_comments_evolved_number( $count ) 
{
    // Override the comment count
    if( function_exists( 'comments_evolved_get_total_count' ) )
        $count = comments_evolved_get_total_count();

    // We must then return the value:
    return $count;
}
add_filter( 'get_comments_number', 'wpse_comments_evolved_number');
然而,在我尝试过的一个网站上,Facebook的数量并没有被拉进来。另一方面,一切都很完美