Home arrow MySQL arrow 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.

TABLE OF CONTENTS:
  1. Building a Simple ColdFusion Content Management System with MySQL
  2. Starting With MySQL
  3. The Page and how to Update/Modify and Delete
  4. Add/Modify Form
  5. Action
  6. Breadcrumb List
  7. Side Menu
  8. Site Map
By: Charles Kaufmann
Rating: starstarstarstarstar / 48
August 11, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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.

1  <cfparam name="baseid" default="1">
2  <cfquery name="menusub" datasource="#variables.data#">
3    select *
4    From tblpages
5    Where status='A'
6    Order by hierarchy
7  </cfquery>
8  <cfoutput query="menusub">
9   <cfif listlen(menusub.hierarchy, "~") gt 1>
10   <cfif listgetat(menusub.hierarchy, 2, "~") eq baseid>
11     <cfloop from="2" to="#listlen(menusub.hierarchy, "~")#" index="i">
12  -
13   </cfloop>
14    <a target="_self" href="page.cfm?id=#menusub.id#" 
15    title="#title#">#title#</a><br>
16   <cfelseif level eq 2> <!--- NON EXPANDED MENU --->
17    - <a target="_self" href="page.cfm?id=#menusub.id#"
18   title="#title#">#title#</a><br>
19   </cfif>
20  <cfelse> <!--- HOME --->
21  <a target="_self" href="page.cfm?id=#menusub.id#"
22  title="#title#">#title#</a><br>
23  </cfif>
24 </cfoutput>

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.



 
 
>>> More MySQL Articles          >>> More By Charles Kaufmann
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

MYSQL ARTICLES

- Oracle Unveils MySQL 5.6
- MySQL Vulnerabilities Threaten Databases
- MySQL Cloud Options Expand with Google Cloud...
- MySQL 5.6 Prepped to Handle Demanding Web Use
- ScaleBase Service Virtualizes MySQL Databases
- Oracle Unveils MySQL Conversion Tools
- Akiban Opens Database Software for MySQL Use...
- Oracle Fixes MySQL Bug
- MySQL Databases Vulnerable to Password Hack
- MySQL: Overview of the ALTER TABLE Statement
- MySQL: How to Use the GRANT Statement
- MySQL: Creating, Listing, and Removing Datab...
- MySQL: Create, Show, and Describe Database T...
- MySQL Data and Table Types
- McAfee Releases Audit Plugin for MySQL Users

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: