Labels in Blogger Classic Template using ColdFusion
Blogger finally got its act together a while back and introduced Labels as a way of tagging or creating categories for blogs. However, they only half-way implemented it for Classic Templates. Each posting lists the Labels that have been assigned to it, and a folder called Labels stores a file listing all the entries for each Label exists. BUT, Blogger doesn't have a $BlogLabel$ tag to display the list of Labels in the navigation column. What's a ColdFusion developer to do? Roll his own!
First, I build the path to the labels folder using ColdFusion functions enabling the code to run in both my development and live environments. Next, the CFDIRECTORY tag returns a list of the files in the Labels folder in a query structure. Looping through the file names using CFOUTPUT tag, I assemble each list element as a link. With the ListFirst function I can treat the filename as a list with the period as the separator and return the filename without an extension giving me the name of the Label.
I store the following code in /blog-cf/labels.cfm and in my Blogger template, I use the following code to call it:
<cfset pathLabels = "#getDirectoryFromPath(getBaseTemplatePath())#labels\">
<cfdirectory name="dirLabels" action="list" directory="#pathLabels#" sort="name asc">
<ul>
<cfoutput query="dirLabels">
<cffile action="read" file="#pathLabels#\#dirLabels.name#" variable="fileLabel">
<li><a href="/blog/labels/#dirLabels.name#">#ListFirst(dirLabels.name,".")#</a></li>
</cfoutput>
</ul>
First, I build the path to the labels folder using ColdFusion functions enabling the code to run in both my development and live environments. Next, the CFDIRECTORY tag returns a list of the files in the Labels folder in a query structure. Looping through the file names using CFOUTPUT tag, I assemble each list element as a link. With the ListFirst function I can treat the filename as a list with the period as the separator and return the filename without an extension giving me the name of the Label.
I store the following code in /blog-cf/labels.cfm and in my Blogger template, I use the following code to call it:
<h2 class="sidebar-title">Labels</h2>
<cfinclude template="/blog-cf/labels.cfm">
Labels: Blogger, ColdFusion
0 Comments:
Post a Comment
<< Home