Display Github Commits in WordPress

When setting up the infrastructure for a project of mine (dianeXu) i tried to incorporate the project repository’s commit atom feed into the project’s WordPress blog.
Sadly the standard RSS widget doesn’t support github’s SSL feeds, so making the feed work with WordPress wasn’t as trivial as it seemed. After some digging and trying a bunch of plugins I stumbled upon this blogpost by Gabriele Romanato (thanks a lot!), explaining how to manually include github’s personal activity feed into WordPress.
Since the commit feed is structured just a little bit different i reworked Gabriele’s code a bit to insert it into a PHP sidebar widget:

$max = $maxitems - 1; 
$i = -1; 
do { 
    $i++; $title = strip_tags($entries[$i]->title); $link = $entries[$i]->link['href']; 
    $content = preg_replace('/' . $title . '/',' :: ',strip_tags($entries[$i]->content),1); 
    if (strlen($content) > 250) { 
        $content = substr($content,0,125) . " ... " . substr($content,(strlen($content)-125),strlen($content)); 
    $date = $entries[$i]->updated; 
    $date_time = strftime('%Y-%m-%d %H:%M:%S', strtotime($date)); 
    $html .= '<li><small>' . $date_time . '</small>' . "\n" . '<h4><a href="' . $link . '">' . $title . '</a></h4>' . "\n". '<p>' . $content . '</p></li>' . "\n";
} while($i < $max); $html .= '</ul>' . "\n"; echo $html; ?>

The modifications change the part of the feed returning the date to the one that’s actually used in the commit feed. They also remove the duplicate title from the content of each feed entry to tidy things up a bit while introducing some useful formatting.

Leave a Reply

Your email address will not be published.