Back

Manually Built Blog RSS with Category Filter

Description

Manually Built Blog RSS with Category Filter.  This goes along with the Blog listing and Blog detail codeshare examples.

Code

${esc.hash}if(${esc.dollar}request.getParameter("cat"))
  ${esc.hash}set(${esc.dollar}catVar=${esc.dollar}request.getParameter("cat"))
  ${esc.hash}set(${esc.dollar}catQuery = "+(categories:${esc.dollar}catVar)")
${esc.hash}end


${esc.hash}set(${esc.dollar}nowsers= ${esc.dollar}date.format('yyyyMMddHHmmss', ${esc.dollar}date.getDate()))
${esc.hash}set(${esc.dollar}finalQuery = "+structureName:Blog ${esc.dollar}!{catQuery} +Blog.sysPublishDate:[19001010101000 TO ${esc.dollar}nowsers]")

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:jf="http://${esc.dollar}{host.hostname}/blogs/rss">
<channel>
<title>Quest Financial Blogs</title>
<link>http://${esc.dollar}{host.hostname}/blogs/</link>
<description>Most Recent ${esc.dollar}!{catVar} - Quest Financial Blog</description>
<language>en-US</language>
<pubDate>${esc.dollar}!{date.format('yyyy-MM-dd', ${esc.dollar}date.getDate())}T${esc.dollar}!{date.format('hh:mm:ss', ${esc.dollar}date.getDate())}</pubDate>
    
${esc.hash}set(${esc.dollar}blogContent= ${esc.dollar}dotcontent.pull("${esc.dollar}{finalQuery}",50,"Blog.sysPublishDate desc"))  
${esc.hash}foreach(${esc.dollar}blogEntry in ${esc.dollar}blogContent)
<item>
  <title>${esc.dollar}webapi.xmlEscape(${esc.dollar}!{blogEntry.title})</title>
  <description>${esc.dollar}webapi.xmlEscape(${esc.dollar}UtilMethods.prettyShortenString("${esc.dollar}blogEntry.body", 200))</description>
  <link>http://${esc.dollar}{host.hostname}/blog/${esc.dollar}blogEntry.urlTitle</link>
  <pubDate>${esc.dollar}!{date.format('yyyy-MM-dd', ${esc.dollar}blogEntry.sysPublishDate)}T${esc.dollar}!{date.format('hh:mm:ss', ${esc.dollar}blogEntry.sysPublishDate)}</pubDate>
  <guid>http://${esc.dollar}{host.hostname}/blog/${esc.dollar}blogEntry.urlTitle</guid>
</item>
${esc.hash}end
</channel>
</rss>

Have you created code you'd like to share with the dotCMS community?

Share your code Become a Contributor