This post is to show how we can create a yearly archive pod in blogCFC. I have recently modified my blogCFC design and I'm really happy on that customization. So the first thing we need to do is adding a new function in the blog.cfc component which is under org > camden > blog folder in your blog root.
<cffunction name="getYearlyArchives" access="remote" returnType="query" output="false"
hint="Function to fetch the blogged years.">
<cfset var getYearlyArchives = "" />
<cfquery name="getYearlyArchives" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
Select year(tblblogentries.posted) as bloggedyears
Where tblblogentries.blog = <cfqueryparam value="#instance.name#" cfsqltype="cf_sql_varchar">
group by year(tblblogentries.posted)
order by bloggedyears desc </cfquery>
<cfreturn getYearlyArchives />
In getYearlyArchives function we are just retrieving the blogged years from tblblogentries table. Next we need to change the code in two important files the first one is parseses.cfm which is under tags folder of your blog root.
<cfif len(trim(sesInfo.categoryName)) and len(trim(sesInfo.categoryName)) lte 50> <!--- translate back ---> <cfset categoryID = application.blog.getCategoryByAlias(sesInfo.categoryName)>
This code need to be replaced with the following code.
<!--- Replacing the '/' with empty string to check the categoryName is in Numeric format. ---> <cfset sesInfo.categoryName = ReplaceNoCase(sesInfo.categoryName,'/','') />
<!--- Checking whether the categoryName is in Numeric format and the length is 4. ---> <cfif len(trim(sesInfo.categoryName)) and IsNumeric(sesInfo.categoryName) and len(trim(sesInfo.categoryName)) eq 4>
Now we have created a new mode called year and assigned the value of categoryName which is nothing but the year to url.year. Next we need edit the getmode.cfm file which is under the same tags folder of your blog. Add this code just below the second cfelseif statement.
<!--- to check the mode is year and year is exist in the url. ---> <cfelseif url.mode is "year" and isDefined("url.year")>
<cfset params.byYear = val(url.year)> <cfset year = val(url.year)>
Here in this code we are setting the selected year value to params.byYear and year parameters. We have done with the code changes and now we can create a pod in blogCFC administrator for to display the list of years in your blog.
<cfprocessingdirective pageencoding='utf-8'> <!---
Name : YearlyArchive.cfm
blogCFC Author : Raymond Camden
Pod Author :Akbarsait(email@example.com)
Created : March 14, 2009
Purpose : Pod to display yearly archives.
Just paste this code in your new pod and save. Check the sidebar of my blog where I have included the yearly archives pod and the existing blogCFC functionality will create the necessary page navigation while clicking the more entries link in your blog. Please let me know if you have any issues in using this code and suggest me if anything is wrong in the above code.