Since the results are loaded asynchronously (meaning we don't know exactly when they are going to be loaded), the easiest way to go about displaying portions of the RSS feeds elsewhere on the page is by modifying the gfeedfetcher.prototype._displayresult() function inside the .js file. This function is invoked when the results have been fully loaded and ready to be shown, hence this is the best place to add in additional code of your own.
Lets say you wish to extend Example 1 on the script page so the description for the 1st, 5th, and 3rd RSS entries are also shown in DIVs of their own on the page:
Code:
<h3>Example 1: (Single RSS feed, 10 entries, "<code>date</code>" field enabled, sort by <code>title</code>)</h3>
<script type="text/javascript">
var cssfeed=new gfeedfetcher("example1", "example1class", "")
cssfeed.addFeed("CSS Drive", "http://www.cssdrive.com/index.php/news/rss_2.0/") //Specify "label" plus URL to RSS feed
cssfeed.displayoptions("date") //show the specified additional fields
cssfeed.setentrycontainer("li") //Display each entry as a list (li element)
cssfeed.filterfeed(10, "title") //Show 10 entries, sort by date
cssfeed.init() //Always call this last
</script>
<br /><br />
RSS Description for <b>1st</b> RSS Entry:
<div id="desc1"></div>
RSS Description for <b>5th</b> RSS Entry:
<div id="desc5"></div>
RSS Description for <b>3rd</b> RSS Entry:
<div id="desc3"></div>
In other words, inside the DIVs highlighted in red. To do this, you'd modify _displayresult() with the below changes:
Code:
gfeedfetcher.prototype._displayresult=function(feeds){
var descs=['desc1', 'desc5', 'desc3']
var rssoutput=(this.itemcontainer=="<li>")? "<ul>\n" : ""
gfeedfetcher._sortarray(feeds, this.sortstring)
for (var i=0; i<feeds.length; i++){
var itemtitle="<a href=\"" + feeds[i].link + "\" target=\"" + this.linktarget + "\" class=\"titlefield\">" + feeds[i].title + "</a>"
var itemlabel=/label/i.test(this.showoptions)? '<span class="labelfield">['+this.feeds[i].ddlabel+']</span>' : " "
var itemdate=gfeedfetcher._formatdate(feeds[i].publishedDate, this.showoptions)
var itemdescription=/description/i.test(this.showoptions)? "<br />"+feeds[i].content : /snippet/i.test(this.showoptions)? "<br />"+feeds[i].contentSnippet : ""
rssoutput+=this.itemcontainer + itemtitle + " " + itemlabel + " " + itemdate + "\n" + itemdescription + this.itemcontainer.replace("<", "</") + "\n\n"
}
rssoutput+=(this.itemcontainer=="<li>")? "</ul>" : ""
this.feedcontainer.innerHTML=rssoutput
for (var i=0; i<descs.length; i++){
var entryindex=parseInt(descs[i].match(/\d+$/i).shift())-1
document.getElementById(descs[i]).innerHTML=feeds[entryindex].content
}
}
The changes tell the script to loop through the array containing the DIV ids [['desc1', 'desc5', 'desc3'], then populate each one with the description of each RSS entry specified by the numeric integer at the end of the ID, so 1=1st entry, 5=5th entry etc. The end result is that these DIVs will now be populated with the respected entry's description.
Bookmarks