I have built a module to read a specific RSS feed and output a list of the feeds. The feed is read like this:

$FeedURL = $params->get('FeedURL');
$rss     = simplexml_load_file($FeedURL);
if ($rss) {
    $items = $rss->channel->item;
    foreach ($items as $item) {
        $title        = $item->title;
        $published_on = $item->pubDate;
        $description  = $item->description;
        $obs          = $item->children("http://www.example.com/");
        $link         = $obs->files->file[0]->fileurl;
        echo '<h3>' . $title . '</h3>';
        echo '<p>(' . $published_on . ')</p>';
        echo '<p>' . $description . '</p>';
        echo '<p><a href="' . $link . '" target="_blank" class="btn">Download PDF</a></p>';

But the feed delivers up to 20 items at once, and subsequent items are obtained by adding &pageIndex=2, &pageIndex=3 etc. to the feed URL. Currently, only the first 20 item are displayed by the module (the feed has about 70 items at the moment, and growing).

How can I modify my module to check if the feed has more than 20 items, and if that's the case, add the items from subsequent pages to the list, or, if possible, add pagination (< Previous and Next >)?

  • I would var_dump($rss) and see if there is anything else in that variable. Seems likely that there should be a piece that tells you. Oct 5 '14 at 15:13

To determine the number of items you could simple use the following after the foreach loop to determine number of items and build out pagination navigation accordingly :

If (count($items) > 20) {

    // Determine current page index
    $index = JFactory::getApplication()->input->get('pageIndex', 1, 'integer');

    // pagination logic here
    $pagination = '';
    if ($index >= 2) {

        // need before button, build link using index minus 1 and create link HTML
        $pagination .= "<a href='" . $previousLink . "'>Previous</a>";


     // build after link using index plus 1 and create link HTML
    $pagination .= "<a href='" . $nextLink . '">Next</a>";

Now, this is untested and requires you to actually buildvthe links, but the core logic is there. Hope this helps, good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.