Last active
January 17, 2016 23:50
-
-
Save leowebguy/0c599100a3b25016641a to your computer and use it in GitHub Desktop.
A simple php code to read medium.com xml rss feed and return data (title, content, image, date) into a page
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
<div class="content"> | |
<h3>MEDIUM POSTS</h3> | |
<div class="row"> | |
<?php | |
$xml = simplexml_load_file('https://medium.com/feed/@leowebdev', null, LIBXML_NOCDATA); | |
function get_image($handler) { //get image from post body | |
preg_match('/src="([^"]*)"/', $handler, $matches); | |
return str_replace('/600/200/','/300/150/',$matches[1]); //change image size from 600x200 into 300x150 | |
} | |
$count = 0; | |
foreach ($xml->channel->item as $item) | |
{ | |
$title = $item->title; | |
$description = $item->description; | |
$link = $item->guid; //you can also use $item->link; | |
$date = $item->pubDate; | |
echo ' | |
<figure class="col-xs-12 col-sm-6 col-lg-6 ' . (++$count%2 ? "clearfix" : "") . '"> | |
<a href="'.$link.'" target="_blank"> | |
<img src="'. get_image($description) .'" alt="'.$title.'" class="img-responsive" /> | |
</a> | |
<figcaption> | |
<div class="details"> | |
<h4>'.$title.'</h4> | |
<span>'.$date.'</span> | |
</div> | |
</figcaption> | |
</figure>'; | |
} ?> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment