Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you already use SimplePie then you can use its <a href="http://simplepie.org/wiki/faq/how_does_simplepie_s_caching_http_conditional_get_system_work" rel="nofollow noreferrer">caching mechanism</a> to have the feed data cached. </p> <p>To combine the articles from internal and external sources create a data structure with all articles. This can be an array of all items sorted by publication timestamp. Then from this array choose the articles for a certain page number.</p> <p>Here's some code to create a combined array of posts. This should give you a idea of the steps involved. The Post class represents a post. The internal and external posts are converted to a Post and stored in the array <strong>$posts</strong>. This array is sorted by timestamp and at the end all posts are echoed.</p> <p><strong>$internalPosts</strong> must contain the posts form your system and <strong>$feedUrls</strong> the URL's of the external feeds. Since I don't know the structure of the internal posts you must adapt the part where internal posts are converted to generic posts.</p> <pre><code>$internalPosts = array(); $feedUrls = array(); include_once 'simplepie.inc'; class Post { public $title; public $link; public $description; public $publishedAt; public function __construct($title, $link, $description, $publishedAt) { $this-&gt;title = $title; $this-&gt;link = $link; $this-&gt;description = $description; $this-&gt;publishedAt = $publishedAt; } } $posts = array(); // Convert internal posts to generic post. foreach($internalPosts as $item){ $posts[] = new Post($item-&gt;title, $item-&gt;link, $item-&gt;description, $item-&gt;publishedAt); } // Retrieve feeds and add posts. $feed = new SimplePie(); foreach($feedUrls as $url){ $feed-&gt;set_feed_url($url); $feed-&gt;init(); foreach ($feed-&gt;get_items() as $item) { $posts[] = new Post($item-&gt;get_title(), $item-&gt;get_link(), $item-&gt;get_description(), $item-&gt;get_date('U')); } } // Sort function. function byPublicationTimestamp($itemA, $itemB){ return ($itemB-&gt;publishedAt - $itemA-&gt;publishedAt); } usort($posts, 'byPublicationTimestamp'); foreach($posts as $post){ echo "&lt;p&gt;&lt;a href='$post-&gt;link'&gt;$post-&gt;title&lt;/a&gt;&lt;br/&gt;" . date('l, j F Y', $post-&gt;publishedAt) . " - $post-&gt;description&lt;/p&gt;"; } </code></pre> <p>For improved performance consider storing the combined articles separately and build the pages from this data. Then you need to update this combined data anytime a new article is published internally or the cached version of an external feed has been refreshed.</p> <p>If you need to publish the external content shortly after it's published on the original site then I would contact those sites to see if it's possible to get a notification of updates instead of waiting for the cached version to expire.</p> <p>EDIT: added sample code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload