I'm no expert in Coldfusion (frankly, I know almost nothing about it), but I've been tasked at work with setting up an Atom feed to show up on one of our client's webpages.
I've managed to get everything wired up correctly, and am able to display the feed on an external website. I'm still having one issue though -- I need a link to the posts, and the feed displays a bunch of different links to the same thing, separated by commas, under that field.
I only need to grab the first one so I can embed it. Is there an easy way to do this without my naive approach of just parsing the string (which I also don't know how to do in CF)?
Here's the code I'm using to generate content now, the linkhref
field is what I need to grab the first member of:
<cfset feedurl="http://*******.blogspot.com/atom.xml" />
<cffeed source="#feedurl#" properties="feedmeta" query="feeditems" />
<ul>
<cfoutput query="feeditems">
<li>#title#</li>
<li>#linkhref#</li>
<li>#content#</li>
</cfoutput>
</ul>
What I'm getting back is something like this: http://*****.blogspot.com/2012/09/****.html,http://****.blogspot.com/feeds/****/comments/default,http://****.blogspot.com/2012/09/****
and so on.
Any help would be greatly appreciated! Thanks!
i'm not sure if I understand your question correctly, but if I do you can use ListFirst()
to get the first list element, so #ListFirst(linkhref)#
would give you the first URL.
For clarity, I would also recommend scoping your variables, so you know exactly where they're coming from.
<cfset feedurl="http://google.blogspot.com/atom.xml" />
<cffeed source="#feedurl#" properties="feedmeta" query="feeditems" />
<ul>
<cfoutput query="feeditems">
<li>#feeditems.title#</li>
<li>#ListFirst(feeditems.linkhref)#</li>
<li>#feeditems.content#</li>
</cfoutput>
</ul>