Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Last active October 5, 2018 17:56
Show Gist options
  • Save stevewithington/2b3016f0d0e3836db298 to your computer and use it in GitHub Desktop.
Save stevewithington/2b3016f0d0e3836db298 to your computer and use it in GitHub Desktop.
Mura CMS: How to loop over categories and output any categorized content.
<cfoutput>
<cfset cats = 'Weather,Local News,Arts & Culture' />
<ul>
<cfloop array="#ListToArray(cats)#" index="c">
<li>
<h3>#HTMLEditFormat(c)#</h3>
<cfscript>
catBean = $.getBean('category').loadBy(name=c, siteid=$.event('siteid'));
feed = $.getBean('feed');
feed.setCategoryID(catBean.getCategoryID());
</cfscript>
<cfif catBean.exists() and feed.getIterator().getRecordcount()>
<cfset it = feed.getIterator() />
<ul>
<cfloop condition="#it.hasNext()#">
<cfset item = it.next() />
<li>
<a href="#item.getURL()#">
#HTMLEditFormat(item.getMenuTitle())#
</a>
</li>
</cfloop>
</ul>
<cfelse>
<!--- either the cateogry doesn't exist, or there's no records --->
</cfif>
</li>
</cfloop>
</ul>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment