Forum

Thread tagged as: Question

Setting up an RSS Feed

Hi!

I need some help setting up an RSS feed to my site. My client uses a shelter manager and wants to integrate their rss onto the site (https://public.sheltermanager.com/animals/gw1124/rss.xml). So I've followed the docs and I'm just a bit confused at where I reference where the feed is coming from?

So I've set up the rss.php page

   <?php include('admin/runtime.php'); ?>
    <?php echo '<'.'?xml version="1.0"?'.'>'; ?>
    <rss version="2.0">
    <channel>
        <title>Available for Adoption</title>
        <link>https://backwell.web-design.wales/available-for-adoption.php</link>
        <description>Animals Available for Adoption at Llys Nini</description>
        <?php
            $opts = array(
                    'page'=>'/available-for-adoption.php',
                    'template'=>'_rss_item.html'
                );
            perch_content_custom('Available for Adoption', $opts);
        ?>
    </channel>
    </rss>

And I've also added this to the available-for-adoption.php page

<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.php" />

Can someone point me in the right direction to tell me what to do?

Thank you!

Jade Marling

Jade Marling 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm just a bit confused at where I reference where the feed is coming from

What do you mean by this?

The RSS is on a thrid party site, so where do I state where the RSS is coming from?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

The docs are for creating an RSS feed from your content, not consuming a third party one.

So I can't do it?

Simon Clay

Simon Clay 127 points

Hi Jade, it is possible to do this, but it's not Perch related. I will dig out my notes and let you know how I did it on another project.

If you could that would be appreciated. Thanks Simon!

Simon Clay

Simon Clay 127 points

Hi Jade, could you just clarify what result you are after?

Are you trying to show an external feed (https://public.sheltermanager.com/animals/gw1124/rss.xml) as a listing on a page on your website?

That's right yes. It will basically be split up into dogs, cats and small animals. Each category will then show a gallery of the animals clicking off onto a details page for them

Hi Simon, did you get chance to find the code for me?

Thanks

Simon Clay

Simon Clay 127 points

Hi Jade,

This code will pull the info from the feed and display it onto your page:

<?php 

    $xml_feed = new DOMDocument();
    $xml_feed->load('https://public.sheltermanager.com/animals/gw1124/rss.xml');
    $feed_items = array();
    foreach ($xml_feed->getElementsByTagName('item') as $node) {
        $item = array ( 
            'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
            'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
            'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
            );
        array_push($feed_items, $item);
    }

    foreach ($feed_items as $feed_item) { ?>
        <div>
            <a href="<?php echo $feed_item["link"] ?>">
                <h4><?php echo $feed_item["title"] ?></h4>
            </a>
            <p><?php echo $feed_item["desc"] ?></p>
        </div>

<?php } ?>