<?php
// Make sure SimplePie is included. You may need to change this to match the location of autoloader.php
// For 1.0-1.2:
#require_once('../simplepie.inc');
// For 1.3+:
require_once __DIR__ . DIRECTORY_SEPARATOR . 'autoloader.php';
// We'll process this feed with all of the default options.
$feed = new SimplePie();
// Set which feed to process.
// Single feed
$feed = new SimplePie();
$feed->set_feed_url(array('http://www.corex-fitness.com/blog/feed/'));
$feed->enable_order_by_date(false);
//$feed->set_cache_location(basename(__DIR__) . '/cache');
$feed->init();
// Run SimplePie.
$feed->init();
// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();
// Let's begin our XHTML webpage code. The DOCTYPE is supposed to be the very first thing, so we'll keep it on the same line as the closing-PHP tag.
//Shorten the description.
function shorten($string, $length)
{
// By default, an ellipsis will be appended to the end of the text.
$suffix = '…';
// Convert 'smart' punctuation to 'dumb' punctuation, strip the HTML tags,
// and convert all tabs and line-break characters to single spaces.
$short_desc = trim(str_replace(array("\r","\n", "\t"), ' ', strip_tags($string)));
// Cut the string to the requested length, and strip any extraneous spaces
// from the beginning and end.
$desc = trim(substr($short_desc, 0, $length));
// Find out what the last displayed character is in the shortened string
$lastchar = substr($desc, -1, 1);
// If the last character is a period, an exclamation point, or a question
// mark, clear out the appended text.
if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';
// Append the text.
$desc .= $suffix;
// Send the new description back to the page.
return $desc;
}
function get_first_image_url($html)
{
if (preg_match('/<img.+?src="(.+?)"/', $html, $matches)) {
return $matches[1];
}
//else return 'url_of_default_image_if_post_has_no_img_tags.jpg';
}
?>
<?php
/*
Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
*/
foreach ($feed->get_items(0, 1) as $item):
?>
<div class=" col-1">
<div class="block block-list">
<div class="block-title"><strong> <span>Blog</span> </strong></div>
<div class="block-content"><?php echo '<img src="' .get_first_image_url($item->get_content()). '"/>'; ?>
<div class="content-title"><a href="<?php echo $item->get_permalink(); ?>" target="_blank"><?php echo $item->get_title(); ?></a></div>
<p><?php echo shorten($item->get_description(), 150); ?></p>
<p>Written on <?php echo $item->get_date('jS F Y'); ?></p>
<p><a href="<?php echo $item->get_permalink(); ?>" target="_blank">Read More</a></p>
</div>
</div>
</div>
<?php endforeach; ?>
Output for git.master, git.master_jit, rfc.property-hooks
Warning: require_once(/in/autoloader.php): Failed to open stream: No such file or directory in /in/8LCTK on line 8
Fatal error: Uncaught Error: Failed opening required '/in/autoloader.php' (include_path='.:') in /in/8LCTK:8
Stack trace:
#0 {main}
thrown in /in/8LCTK on line 8
Process exited with code 255.
This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.