我有一个生成带有ColdFusion及其CFFeed
标记的xml文件的脚本。除图像外,它的效果非常好。我知道你必须使用封装CDATA
中的图像才能显示它。我不确定我是否已正确设置,因为我的Google阅读器/ Feedly Feed中没有显示图片。这是代码:
<cfquery datasource="data" name="queryT">
SELECT *
FROM qTable
WHERE ...
ORDER BY...
</cfquery>
<cfset RssStruct = StructNew() />
<cfset RssStruct.link = "https://www.url.com" />
<cfset RssStruct.title = "sitename" />
<cfset RssStruct.description = "url Blog" />
<cfset RssStruct.image.url = 'https://www.url.com/assets/img/ns.png' />
<cfset RssStruct.image.title = 'Site Name' />
<cfset RssStruct.image.link = 'https://www.url.com' />
<cfset RssStruct.pubDate = Now() />
<cfset RssStruct.version = "rss_2.0" />
<cfset RssStruct.item = ArrayNew(1) />
<cfset threadlist = "">
<cfset index = 1>
<cfloop query="queryT">
<cfif listcontains( threadlist , '#id#' ) eq 0>
<cfset threadlist = ListAppend(threadlist, '#id#')>
<!--- Here let's clean up and ensure that all values are XML Compliant --->
<cfset RssStruct.item[index] = StructNew() />
<cfset RssStruct.item[index].guid = structNew() />
<cfset RssStruct.item[index].guid.isPermaLink ="YES" />
<cfset RssStruct.item[index].guid.value = 'https://www.url.com/page.cfm?itemid=#queryT.id#' />
<cfset RssStruct.item[index].pubDate = createDate(year(Posted), month(Posted), day(Posted)) />
<cfset RssStruct.item[index].title = xmlFormat(#title#) />
<cfset RssStruct.item[index].Body = xmlFormat(#Body#) />
<cfset RssStruct.item[index].description = StructNew() />
<cfset RssStruct.item[index].description.value = '<![CDATA[ <img src="https://www.url.com/assets/Photos/photo/#id#.jpg"> #body# ]]>' />
<cfset RssStruct.item[index].link = 'https://www.url.com/page.cfm?item=#queryT.id#' /><br>
<cfset index = index + 1>
</cfif>
</cfloop>
<!--- Generate the feed and save it to a file and variable. --->
<cffeed action="create" name="#RssStruct#" overwrite="true" xmlVar="myXML" outputFile = "Feed.xml" />`
答案 0 :(得分:1)
看起来您已为项目下的<description>
元素创建了一个结构。您是否尝试过简单地将代码放入<description>
?
而不是:
<cfset RssStruct.item[index].description = StructNew() />
<cfset RssStruct.item[index].description.value = '<![CDATA[ <img src="https://www.url.com/assets/Photos/photo/#id#.jpg"> #body# ]]>' />
试试这个:
<cfset RssStruct.item[index].description = '<![CDATA[ <img src="https://www.url.com/assets/Photos/photo/#id#.jpg"> #body# ]]>' />
您是否尝试过使用该项目的<enclosure>
元素?
定义和用法
该元素允许媒体文件包含在项目中。
<强>属性强>
长度 - 必填。定义媒体文件的长度(以字节为单位)
类型 - 必填。定义媒体文件的类型
url - 必填。定义媒体文件的URL
一个例子就是(你需要确定图像的大小,以字节为单位):
<enclosure url="https://www.url.com/assets/Photos/photo/#id#.jpg" length="#ImageLength#" type="image/jpeg" />