Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在WordPress中的PHP函数内调用FQL子查询_Php_Facebook_Wordpress_Facebook Fql - Fatal编程技术网

在WordPress中的PHP函数内调用FQL子查询

在WordPress中的PHP函数内调用FQL子查询,php,facebook,wordpress,facebook-fql,Php,Facebook,Wordpress,Facebook Fql,我在WordPress中的functions.php文件中使用了下面的函数,该函数用于调用指定的子查询,以显示特定链接在facebook上的总份额、喜好、评论等 function fb_echoes($type) { global $post; $url = get_permalink($post->ID); $fbconfig['appid' ] = "1427040634231404"; $fbconfig['secret'] = "49a95c1eb6f7862caa8f66b

我在WordPress中的functions.php文件中使用了下面的函数,该函数用于调用指定的子查询,以显示特定链接在facebook上的总份额、喜好、评论等

function fb_echoes($type) {
global $post;
$url = get_permalink($post->ID);

$fbconfig['appid' ]  = "1427040634231404";
$fbconfig['secret']  = "49a95c1eb6f7862caa8f66b04c87318d";
include_once "facebook.php";

$facebook = new Facebook(array(
    'appId'  => $fbconfig['appid' ],
    'secret' => $fbconfig['secret'],
    'cookie' => true
));

$fql = "SELECT url, normalized_url, share_count, like_count, comment_count, total_count, commentsbox_count, comments_fbid, click_count FROM link_stat WHERE url = '".$url."' ";
$param  =   array(
    'method'    => 'fql.query',
    'query'     => $fql,
    'callback'  => ''
);
$fqlResult   =   $facebook->api($param);
return $fqlResult[0][$type];
}
要显示页面中任意位置的facebook评论数,我使用以下代码:

<?php echo fb_echoes(commentsbox_count) ?>
我已经禁用了默认的可湿性粉剂评论,但是帖子和主页上的小计数图标显示了可湿性粉剂评论的计数。我想在那边显示FB评论计数。下面的代码显示默认注释计数:

function it_get_comments($args) {
extract($args);
$tooltip = '';
$comments = get_comments_number($postid);
$label_text=__(' comments',IT_TEXTDOMAIN);
if($comments==1) $label_text=__(' comment',IT_TEXTDOMAIN);
if(empty($tooltip_hide)) $tooltip = ' info-bottom';
$out='<span class="metric' . $tooltip . '" title="'.__('Comments',IT_TEXTDOMAIN).'">';
if($comments>0 || $showifempty) {
    if($anchor_link) '<a href="#comments">';
        if($icon) $out.='<span class="icon icon-commented"></span>';
        $out.='<span class="numcount">' .$comments;
        if($label) $out.=$label_text;
        $out.='</span>';
    if($anchor_link) '</a>';
}
$out.='</span>';
return $out;
}
如何将commentsbox fql子查询调用到此函数中,并将WP注释计数覆盖到FB注释计数

get_comments_number函数在返回结果之前通过过滤器get_comments_number过滤结果,因此,如果您连接到此过滤器,您将能够使用Facebook函数的结果覆盖这些值

function facebook_get_comments_number( $count, $post_id ){
    return fb_echoes( 'commentsbox_count' );
}
add_filter( 'get_comments_number', 'facebook_get_comments_number', 10, 2 );
另外,当代码正常工作时,您不应该在fb_echoos的参数周围使用单引号,否则PHP会将其视为常量,并且在其后面加上分号也是一种很好的形式:

<?php echo fb_echoes( 'commentsbox_count' ); ?>

好吧,那东西很管用,但我想展示的是我的帖子,在标题上方有一个小聊天图标,旁边是帖子上的总评论。我删除了该代码,并在那里调用了fb_回声,但它只显示了数字,没有任何图标和样式。这用于显示注释的数量,变量有:$commentsargs=array'postid'=>get\u ID,'label'=>true,'icon'=>true,'showifempty'=>true,'tooltip\u hide'=>true,'anchor\u link'=>true;那么,如何显示这些值,使数字显示在上面问题中给出的php函数中所描述的html标记中。这是特定于您的主题的,因此我无法真正提供帮助,但您可能只需要将其更改回原始值