我在一个客户的网站上工作,更新到ColdFusion 8是不可行的。我正在寻找的是通过自定义标记或组件实现类似于CF8的CFFEED功能的东西,如果已经存在一些东西,我并不是特别热衷于编写我自己的阅读器/解析器。
我需要从博客中读取RSS2馈送,并显示标题,描述和链接。我最好能够设置一个大约5-10分钟的缓存,这样我就不会敲击提要(我从提要中提取的信息将显示在高流量的网站上)。
发布于 2009-08-11 01:25:25
如果你正在寻找开箱即用的东西,在RIAForge上有几个项目,快速搜索一下就会发现这两个,但我猜你可以找到更多:
http://cfrss.riaforge.org/
http://rssville.riaforge.org/
如果你想自己滚动(我知道你说过你不喜欢),你就不能像这样请求提要吗:
<cfhttp
url = "http://example.com"
resolveurl="no"
throwOnError = "yes"
timeout = "10" >
</cfhttp>并解析结果:
<cfset feedData = CFHTTP.FileContent>
<cfset xmlData = XMLParse(feedData)>循环遍历:
<cfset result = queryNew("title,description")>
<cfset items = xmlSearch(xmlData,"//*[local-name() = 'item']")>
<cfloop index="x" from="1" to="#arrayLen(items)#">
<cfif structKeyExists(items[x],"title")>
<cfset node.title = items[x].title.XmlText>
<cfelse>
<cfset node.title = "">
</cfif>
<cfif structKeyExists(items[x],"description")>
<cfset node.description = items[x].description.XmlText>
<cfelse>
<cfset node.description = "">
</cfif>
<cfset queryAddRow(result)>
<cfset querySetCell(result,"title",node.title)>
<cfset querySetCell(result,"description",node.description)>
</cfloop>输出:
<cfoutput query="result">
<ul>
<li><strong>#title#</strong> - #description#</li>
</ul>
</cfoutput>显然没有经过测试,但这仍然是一个想法。使用类似的东西来获得我最新的美味书签。就缓存而言,有几种不同的方法来处理它。我可能会运行一个计划任务来访问这个文件,并将输出写到一个单独的文件中。我相信有更好的方法,但这是快速和肮脏的,我的。
发布于 2013-06-19 04:11:00
我知道这有点晚了,但在我的工作中遇到了这种情况(Coldfuison 7和将不会升级)。而且还需要从我们网站上的嵌入位置链接回原始帖子。
只需在上面的答案中再添加一点,您可以添加此链接,以链接回循环中的文章(在我们的例子中是关于tumbler ):
<cfif structKeyExists(items[x],"guid")>
<cfset node.guid = items[x].guid.XmlText>
<cfelse>
<cfset node.guid = "">
</cfif>
<cfset querySetCell(result,"guid",node.guid)>在输出中:
<a href="#guid#">#title#</a>我相信你也可以用"link“代替"guid",但这对我很有效。我希望这能帮助其他需要链接回来的人。我是ColdFusion的新手,可能有更好的方法(在旧版本的CF上)。
https://stackoverflow.com/questions/1258040
复制相似问题