Quantcast
Channel: Blogosys » RSS Feed
Viewing all articles
Browse latest Browse all 10

How to Use Functionality of SimplePie in WordPress?

$
0
0

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


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images