Created
July 13, 2012 16:55
-
-
Save piercemoore/3105963 to your computer and use it in GitHub Desktop.
Quick Reddit reader in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Full disclosure: I wrote this while writing a Twitter Bootstrap enabled site, so the class tags are Twitter bootstrap enabled. Shouldn't be hard to style, though. | |
$subReddit = "webdev"; // Enter the subreddit name here with no /r/ in front | |
$selfTextLimit = 250; // Character limit for self text entries | |
$pageData = json_decode( file_get_contents( "http://www.reddit.com/r/$subReddit/.json" ) ); | |
foreach( $pageData->data->children as $post ): ?> | |
<div class="well"> | |
<h2> | |
<a href="<?=$post->data->permalink;?>" target="_blank"><?=$post->data->title;?></a> | |
<a href="<?=$post->data->url;?>" target="_blank" class="btn btn-primary btn-mini"> | |
<i class="icon-share"></i> Link | |
</a> | |
</h2> | |
<p><?=substr( $post->data->selftext_html , 0 , $selfTextLimit );?></p> | |
<span class="label label-success"><i class="icon-chevron-up"></i> <?=$post->data->ups;?></span> | | |
<span class="label label-important"><i class="icon-chevron-down"></i> <?=$post->data->downs;?></span> | | |
<span class="label label-default"><?=$post->data->num_comments;?> comments</span> | |
</div> | |
<?php endforeach; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment