Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7709799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:57:11+00:00 2026-06-01T00:57:11+00:00

So what i have in mind is showing a list with most popular posts

  • 0

So what i have in mind is showing a list with most popular posts based on how many facebook comments they have. I already managed to make a function that counts based facebook graph how many comments a post has, but i am having problem with the query:

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

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

<?php if ($count == 0) { ?>
         <span>No comment</span>
<?php } elseif ($count == 1) { ?>
         <span>One Comment</span>
<?php } elseif ($count > 1 ) { ?>
         <span><?php echo $count; ?> Comments</span>

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:57:12+00:00Added an answer on June 1, 2026 at 12:57 am

    You may want to store number of comments to post meta-data so you’ll be able to use it for sorting later.

    BTW, your function will not work due to difference in response format you use and the real response. (number of comments is present in response->comments->count and not in response->comments). Also you may wish to use fields=comments to limit the response to only include details about comments without all the rest of data or using FQL query to retrieve only count of comments:

    SELECT commentsbox_count FROM link_stat WHERE url = 'POST_URL'
    

    The flow as I see it may be so:

    • Store number of comments within post-meta
    • Update number of comments calling fb_comment_count once post is viewed
    • Use query_posts with meta_key to change the defaults.
    function fb_comment_count() {
      global $post;
      $url = get_permalink($post->ID);
    
      $query = "SELECT commentsbox_count FROM link_stat WHERE url = '{$url}'";
      $responseText = file_get_contents('https://graph.facebook.com/fql?q='.$query);
      $responseJson = json_decode($responseText);
    
      $commenteCount = $responseJson->data->commentsbox_count;
      update_post_meta($post->ID, 'facebook_comments_count, $commenteCount);
      // ...
    }
    

    Once your posts have facebook_comments_count meta you can use query_posts in The Loop:

    query_posts('posts_per_page=5&meta_key=facebook_comments_count&orderby=meta_value&order=DESC')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a train based game in Facebook Javascript. I have an inverted
Here is what I have in mind: 1) Create a service that will run
This is what I have in mind: Can anyone point out some relevant resources?
I'm new to Django, but the application that I have in mind might end
I have something in my mind which have been bothering me for quite a
I'm new to c++ but have set my mind on a specific task that
I have a project in mind whose main selling point would be very good
I have a project in mind that will require the majority of queries to
I have a project in mind that will offer users their own domain, like
I have a specific case in mind, but the question applies in general too.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.