SimplePie 1.3.1 is now available. Upgrade now!

SimplePie Documentation.  Learn how to use this thing.  It's way better than going to school.

You are here: Documentation » API Reference » SimplePie » Extending the SimplePie class

Extending the SimplePie class

Description

Whereas other classes can be extended with specific methods (listed below in the API Reference), SimplePie can be overloaded directly.

Learn more about extending classes in PHP:

Availability

  • Available since SimplePie Preview Release.

Examples

Replace a method and add a method

<?php
require_once('../simplepie.inc');
 
// Create a new class that extends an existing class
class SimplePie_Extras extends SimplePie {
 
	/**
	These are examples of adding new methods to an existing class.
	 */
 
	function read_in_simplereader_mobile()
	{
		return $this->subscribe_service('http://mobile.simplereader.com/?feed=');		
	}
 
	function get_feed_title()
	{
		return $this->get_title();
	}
 
}
 
// Let's do our standard SimplePie thing, except that we call SimplePie_Extras instead of SimplePie.
$feed = new SimplePie_Extras();
$feed->set_feed_url('http://simplepie.org/blog/feed/');
$feed->init();
$feed->handle_content_type();
?>
 
<html>
<body>
 
<h1><?php echo $feed->get_feed_title(); ?></h1>
<p><small><a href="<?php echo $feed->read_in_simplereader_mobile(); ?>">Read in SimpleReader Mobile!</a></small></p>
<hr />
 
<?php foreach ($feed->get_items(0,5) as $item): ?>
 
	<h4><a href="<?php echo $item->get_permalink()?>"><?php echo $item->get_title()?></a></h4>
	<p><small><?php echo $item->get_date('j F Y, g:i a')?></small></p>
	<p><?php echo $item->get_description()?></p>
	<hr />
 
<?php endforeach; ?>
 
</body>
</html>

See Also


reference/simplepie/extending_the_simplepie_class.txt · Last modified: 2011/03/05 19:56 (external edit)