Tuesday, January 1, 2013

Display latest Disqus entries

I recently added disqus to a website and wanted to promote it by listing the latest entries on the home page. Unfortunately, Disqus no longer offer ready made widgets for this. There is an API that can be used, but it's even simpler to use the RSS feed. Below are some pseudo PHP code that use magpie to fetch the RSS stream and get the corresponding variables.

Example of usage can be seen at http://www.karinboye.se/index.shtml (in Swedish).

require_once 'magpierss/rss_fetch.inc';
$url = 'http://your_disqus_id.disqus.com/latest.rss';

$rss = fetch_rss($url);

echo "Site: ", $rss->channel['title'], "<br>";

foreach ($rss->items as $item ) {     

     $title   = $item['title'];
     $text    = $item['description'];
     $creator = $item['dc']['creator'];
     $date    = $item['dc']['pubdate'];
     $url     = $item[link];
     echo "<a href=$url>$title</a><br>";
     echo "$text<br>";
     echo "$creator<br>";
     echo "$date<br>";

}


No comments:

Post a Comment