How to Use Functionality of SimplePie in WordPress?


Here i will show you how to use SimplePie functionality in WordPress templates. I presume that you have the basic understanding of SimplePie and know how to add PHP code to your WordPress template. If you are beginner and don’t have enough knowledge on SimplePie than i recommend to read SimplePie wiki first.

To use SimplePie in WordPress template you need to include ‘feed.php‘ which is present in wp-includes folder. This file contains functions which are used in WordPress to deal with Feeds. The file also contains fetch_feed() function which is used to build SimplePie object RSS and ATOM from URL.

Find the example code snippet below-


<?php

//WORDPRESS modified
include_once(ABSPATH . WPINC . '/feed.php');

// Get a SimplePie feed object from the specified feed source.
$feed = fetch_feed('http://themeappears.com/premiumwordpresstemplates/feed/rss/');

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<title>SimplePie In WordPress Template</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>

	<div class="header">
		<h1><a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a></h1>
		<p><?php echo $feed->get_description(); ?></p>
	</div>

	<?php

	foreach ($feed->get_items() as $item):
	?>

		<div class="item">
			<h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
			<p><?php echo $item->get_description(); ?></p>
		</div>

	<?php endforeach; ?>

</body>
</html>

where ABSPATH – Absolute path of the WordPress Installation and WPINC – WordPress include folder which is ‘wp-includes

Featured Items - Ultimate Collection of Responsive WordPress Themes

Responsive WordPress themes enables stunning look and feel of your website in any device - from mobile devices to widescreen monitors. These collections are sorted by user rating and number of sales.
FIND OUT MORE

Featured Items - WebHostingPad Starts at only $1.99/Month

WebHostingPad is a Cheap, Easy and Affordable web hosting provider with Free Website Builder and Website Transfer. They are running SPECIAL LIMITED PERIOD OFFER $1.99/month (Regularly $4.95.mo).
FIND OUT MORE

Featured Items - Collection of Best Premium Portfolio WordPress themes

Need to showcase your project work in a stunning way? These premium Portfolio WordPress themes will make your work easy for you. Perfect for showcasing Project, Photography, Video and Art work.
FIND OUT MORE

Featured Items - Start Your Own Community Website Like Facebook In a Minute

Want to start your own social or community website like Facebook ? Start right away using Buddypress WordPress plugin along with premium Buddypress Themes. No need to setup anything. It works out of box. Install BuddyPress plugin and Premium themes from this list. Your are done!.
FIND OUT MORE

Featured Items - Recommended WordPress and Web Development Books

Want to learn IN and OUT of web development and become professional web developer? Here are the list of WordPress and Web Development books which i recommend you to start with.
FIND OUT MORE

, , , ,