2011-07-20 213 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

回答