HomeMySQL Page 7 - Building a Simple ColdFusion Content Management System with MySQL
Side Menu - MySQL
This tutorial lays out the basics for creating a content management system in ColdFusion and MySQL. The System leverages hierarchical data to automatically build breadcrumb lists, a side navigation menu, as well as a site map. The goal of this tutorial is to provide a framework upon which to build a content management system that is easy to customize and maintain, leaving the web author more time to create content than maintain code.
As I stated above, this menu is designed to show up on the side of the page, and that it will expand if you are within a subsection of the home page. For example if your web site had several major sections, Carpentry and Stamp Collecting. If someone clicked on Stamp Collecting, all of the child pages would expand (similar to browsing for files, you click on a folder and the sub folders become visible).
Let look at the code. You can either include this in the menu section of your site or create a new page with this code and CFINCLUDE it in.
So now let's walk through the above section of code. I create a CFPARAM for the baseid variable and set its default to 1. This is so you can run pages that you may create that do not run off of this content management system. Due to the fact that it does not run off the content management system it will not have a baseid. The CFPARAM keeps it from throwing an error.
The CFQUERY on lines 2 through 7 queries out all of your active records and order them by the HIERARCHY field. Line 8 starts the CFOUTPUT of the menu listing. Line 9 starts a CFIF that checks the length of the hierarchy list. If the length is 1 then it is the home page which is dealt with on lines 20 to 23. Line 10 gets back to a variable we created while making the breadcrumb list, the Baseid. We use this variable to check to see if the child off of the homepage is part of the hierarchy you are looking at. If so we are going to expand all the child links from the page with the Baseid. All of the other pages that have a hierarchy level 2 that are not the baseid, will not expand their child pages . If you did not want this to happen you could take out the CFIF and its parts out of line 10. Lines 11 through 13 are just for decoration. That section loops through the hierarchy list length and shows the dashes accordingly. In the CFLOOP I started with 2 in the FROM attribute so that the child pages of the home page would not have a dash in front of them. You could put anything you want in this loop, even spaces. Lines 14 through 15 build the link by using the title and the ID of the record. Lines 16 through 19 finish off the CFIF statement by showing the child pages off of the home page without expanding them. Lines 20 to the end simply display the link for the home page. For this one, since you know exactly what the page is going to be, instead of querying out the title, you could manually code the name (e.g. your site name or use an image).
That is it for the side menu, the breadcrumb list and also the page itself. As an added bonus however, I am going to throw in a self building site map.