cffeed 函数:仅显示最近的帖子?
我们有一个功能可以使用以下代码提取 RSS 提要并在 ColdFusion 页面上显示帖子:
<cfset rssUrl = "rss1">
<cffeed action="read" source="#rssUrl#" query="fitness" properties="info">
<cfset rssUrl2 = "rss2">
<cffeed action="read" source="#rssUrl2#" query="nutrition" properties="info">
<cfif #fitness.PUBLISHEDDATE# gt #nutrition.PUBLISHEDDATE#>
<cfset entries="fitness">
<cfelse>
<cfset entries="nutrition">
</cfif>
输出完成方式:
<cfoutput query="#entries#">
问题是,RSS 提要有多个帖子,而我们只想显示一个。关于如何让它只拉出并显示最新的帖子有什么想法吗? (我们希望 feed 有多个帖子,所以现在我们的非理想解决方案是将每个 feed 的最大帖子数设置为 1)
We have a function to pull RSS feeds and display the post on a ColdFusion page using this code:
<cfset rssUrl = "rss1">
<cffeed action="read" source="#rssUrl#" query="fitness" properties="info">
<cfset rssUrl2 = "rss2">
<cffeed action="read" source="#rssUrl2#" query="nutrition" properties="info">
<cfif #fitness.PUBLISHEDDATE# gt #nutrition.PUBLISHEDDATE#>
<cfset entries="fitness">
<cfelse>
<cfset entries="nutrition">
</cfif>
Output done via:
<cfoutput query="#entries#">
Problem is, the RSS feed has several posts and we only want to show one. Any thoughts on how to get it to pull and display only the most recent post? (We want the feed to have multiple posts, so right now our non ideal solution is to set maximum posts per feed to 1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
cfoutput/query=".."
将遍历整个查询。如果您只想执行第一行,请使用:Basically - 列上的数组表示法。有道理吗?
cfoutput/query=".."
will go over an entire query. If you only want to do the first row, use:Basically - array notation on the column. Make sense?
Ray 的回答没有任何问题,但这里还有一些其他选项。
对现有代码的干扰最小,如果您决定更改显示的行数(例如通过用户设置),这是一个简单的更改。
或者
如果您复制查询对象而不是查询名称(实际上不是副本,而是引用副本),
则
可以这样做
,默认情况下,仅显示第一行的查询。
There's nothing wrong with Ray's answer, but here are some other options.
Offers the least disruption to your existing code and, should you decide to change the number of rows displayed (like, via a user setting) it's an easy change.
OR
If you copy the query object rather than the query name (which isn't actually a copy but a copy by reference)
instead of
you can do this
which will, by default, display only the first row of the query.