Sidebar

startup_tutorial_and_checklist:feature_configuration:exporting_listings:rss_feed:displaying_rss_in_other_sites

Display RSS Feed In Other Sites/Webpages

This tutorial should describe how you can display your RSS feed within another webpage outside your software. That could be on another website or within other pages of your site outside the Geo software.

To do this you essentially place two bits of javascript code within the page you want to display the RSS feed within. The first bit of code does all the work of getting the feed and formatting it for the page you are about to display it in. You would place the following code within the html head of the page:

<!--gets the jquery to do the job -->
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<!--script that does the work -->
<script type="text/javascript" >
function parseRSS(rssurl, container) {
	$.get(rssurl, function(data) {
		var $xml = $(data);
		$xml.find("item").each(function() {
			var $this = $(this),
				item = {
					title: $this.find("title").text(),
					link: $this.find("link").text(),
					description: $this.find("description").text(),
					pubDate: $this.find("pubDate").text(),
					author: $this.find("author").text()
			}
			//This determines what each item in the feed will look like
                        //The data above is available to place within the html below
                        //note that you can change the following html to what you like and to include what you want from the above.
                        //we styled through the div but you can place your own html to style as you like
			
			var thehtml = '<div><h4><a href="'+item.link+'" target="_blank">'+item.title+'</a></h4><p class="feed-item-desc">'+item.description+'</p></div>';

			$(container).append(thehtml);  //append this RSS feed item to the output placed in the feed div shown below
			
		});
	});
}
</script>

And then you would place this code in the exact place within the html of that page you wanted the RSS feed to appear:

<div id="thisrssfeed" class="feedcontainer"></div>

<script type="text/javascript">
$(function(){
 // running custom RSS functions
 parseRSS('http://www.example.com/rss_listings.php',
'#thisrssfeed')
});
</script>

The url you see above should be the full url to the feed you want to display. As you know by reading about the RSS feature you can pass in variables within the query string to display specific listings. You can also setup whole different files for each rss feed you want to display. What ever the url place it where you see the url above. The "#thisrssfeed" bit should point to the id of the div where the items from the feed will display. You can then style the RSS feed using the class you attach to the div around the feed. In the above we use "feedcontainer" to name that class but you can style as you wish.

All the above code can work in any html page. It is all javascript and does not require php of any kind to work.

startup_tutorial_and_checklist/feature_configuration/exporting_listings/rss_feed/displaying_rss_in_other_sites.txt · Last modified: 2017/10/18 07:47 by geomatt