<!--- 
This code will consume a long atom feed and display entries that are marked with a specific category.
Written by Michael McIntire http://brickblog.net
September 2007.
Use is as-is, with no warranty. 
Please feel free to use, modify and distribute. 
Credit is appreciated, but not mandatory.

--->



<!--- --------------------------------------------------------------- --->
<!--- User Variables ------------------------------------------------ --->
<!--- Use these variables to set the feed url and the category        --->
<!--- of posts to display. 											  --->
<!--- --------------------------------------------------------------- --->

<!--- Full url to Atom Feed --->
<cfset feed_address = "">
<!--- Category of posts to display --->
<cfset pull_cat = "tip of the week">
<!--- How many charecters of the post do you want to display? --->
<!--- Default 0, displays entire post, this includes html markup for now, so be careful. --->
<cfset displayChar = 0>



<!--- No need to change below this, unless changing functionality. --->
<!--- Name of xml child to process --->
<cfset xmlChild = "entry">

<cftry>
	<!--- Get the feed, establish that it is xml and find how many entries there are. --->
    <cfhttp url="#feed_address#" method="get">
    <cfset feedXML = xmlparse(cfhttp.fileContent)>
    <cfset numEntries = ArrayLen(feedXML.feed.entry.XmlChildren)>
    <cfset MyArray = feedxml.xmlroot.xmlchildren>
    <cfset Posts = arraynew(1)>

    <cfcatch type="any">
        There was an error with the feed.
    </cfcatch>
</cftry>

<cftry>
    <cfloop from="1" to="#arraylen(myarray)#" index="j">
        <cfoutput>
            <cfif myarray[j].xmlname eq #xmlChild#>
                <cfset posts[arraylen(posts)+1] = myarray[j]>
            </cfif>
        </cfoutput>
    </cfloop>
    
    
    <cfoutput>
    
    <!--- Loop through posts --->	
    <cfloop from="1" to="#arraylen(posts)#" index="k">
        
        <!--- Loop through post categories --->
        <cfloop from="1" to="#arraylen(posts[k].category)#" index="i">
            <!--- Find the desired category --->
            <cfif #trim(posts[k].category[i].xmlattributes.term)# eq #pull_cat#>
                <cfset articleTitle = #posts[k].title.xmltext#>
                <cfset articleContent = #posts[k].content.xmltext#>
                <cfset articleLink = #posts[k].link.xmlattributes.href#>
                 <cfif #displayChar# gt 0>
                    	<cfset articleContent = "#left(articleContent, displayChar)# . . . <a href='#articleLink#' target='_blank'>Read More</a>">
                    </cfif>
                
                
                 <h1><a href="#articleLink#" target="_blank">#articleTitle#</a></h1>
                   
                    
                    #articleContent#
                
            </cfif>
        </cfloop>
        
     </cfloop>   
        
    </cfoutput>
    
    <cfcatch type="any">
        There was an error processing the feed
    </cfcatch>
</cftry>

