Creating a Yearly Archives Pod in blogCFC

  Mar 14, 2009     10364 Views      BlogCFC , ColdFusion       Comments (3)   

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
   From    tblblogentries
   Where    tblblogentries.blog = <cfqueryparam value="#instance.name#" cfsqltype="cf_sql_varchar">
   group by year(tblblogentries.posted)
   order by bloggedyears desc
</cfquery>

<cfreturn getYearlyArchives />

</cffunction>

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)>

<cfif len(categoryID)>

<cfset url.mode = "cat">
<cfset url.catid = categoryID>

</cfif>

</cfif>

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>

<cfset url.mode = "year">
<cfset url.year = sesInfo.categoryName>

<cfelseif len(trim(sesInfo.categoryName)) and len(trim(sesInfo.categoryName)) lte 50>

<!--- translate back --->
<cfset categoryID = application.blog.getCategoryByAlias(sesInfo.categoryName)>

<cfif len(categoryID)>

<cfset url.mode = "cat">
<cfset url.catid = categoryID>

</cfif>

</cfif>

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(akbarsaitn.cfmx@gmail.com)
Created : March 14, 2009
Purpose : Pod to display yearly archives.
--->


<cfoutput>

<cfmodule template="../../tags/scopecache.cfm" cachename="pod_yearlyarchives" scope="application" timeout="#application.timeout#">

<cfmodule template="../../tags/podlayout.cfm" title="Yearly Archives">

<cfset yearlyArchives = application.blog.getYearlyArchives() />

<cfloop query="yearlyArchives">

<a href="#application.blog.getProperty("blogurl")#/#bloggedYears#/">
#bloggedYears#
</a><br/>

</cfloop>

</cfmodule>

</cfoutput>      

<cfsetting enablecfoutputonly='false'/>

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.

Related Entries


Comments

1. anjali on Feb 18, 2010 at 10:18 AM

Hey Nice work!!

Will the same way works for monthly archives?

If yes, can you please give me the steps.

Thank you

2. Akbarsait on Feb 20, 2010 at 4:59 AM

@anjali,

You can follow the steps for creating the Monthly Archive at Rob Brooks-Bilson's Blog here - http://ur.ly/4euv

3. anjali on Feb 23, 2010 at 11:22 AM

Thanks for your reply Akbar,
But i tried it. I liked the way how you did. Anyway thank you, I will try to do with Rob's code.

You have a good week.

About Me

CFML/Web/Cloud/Data/Agile Enthusiast, Husband & Dad, an avid learner & android fan who works as a Tech Consultant in Toronto, Canada.

GetCFMLJobs.com!
Get Your Next CFML Job!
ColdFusion Tuts
ColdFusion Tutorials & Resources


Categories

Adobe Agile AppCore Creator BlogCFC Books Bootstrap CFBuilder CFEclipse CFML Chennai CFUG Chrome Extensions ColdFusion Google IIS India Learning MySQL Railo Subversion Tools & Utilities Web Windows 7


Archives

2021 2018 2017 2016 2014 2013 2012 2011 2010 2009 2008

Search


Akbarsait © 2008 - 2023 | Hosting provided by Vivio Technologies

Home | Blog | Sitemap | RSS Feed