2011-07-20 63 views
0

全局$ post变量未在此处设置。我如何设置它?

function fb_comment_count($link = 'link') { 
    global $post; 
    $url = 'https://graph.facebook.com/'; 
    $posturl = get_permalink($post->ID); 
    $url .= $posturl; 

    $filecontent = wp_remote_retrieve_body(wp_remote_get($url, array('sslverify'=>false))); 
    $json = json_decode($filecontent); 
    $count = $json->comments; 
    if ($count == 0 || !isset($count)) { 
    $count = 0; 
    } 

    $comments = $count; 
    if ($count == 1) { 
    $comments .= ''; 
    } 
    elseif ($count == 0) { 
    $comments = '0'; 
    } 
    elseif ($count > 1) { 
    $comments .= ''; 
    } 
    if ($link == 'nolink') { 
    return $comments; 
    } 
    else { 
    return '<a href="'.$posturl.'#comments" title="Comments for '.$post->post_title.'">'.$comments.'</a>'; 
    } 
} 
+1

你从哪儿打电话呢?您可能需要传入$ post变量或至少一个id,以便您可以从中检索该帖子。 – mrtsherman

+0

也许你的意思是$ _POST? – 2011-07-20 03:56:48

回答