This was good then... but is there a better way now? Scott Offord
This tutorial demonstrates how to generate a dynamic sitemap for a ColdFusion database-driven website, assuming that you retrieve the content of your website from a database and you save the website content according to the concept of "Parent" and "Parent ID".
Let's say that you save your website content (through a content management system or a content publishing tool) in the following database table (name it "content" for example). Example:
| ID | PARENT_ID | TITLE | CONTENT | WEIGHT |
| 1 | 0 | Home | Content of this section... | 1 |
| 2 | 0 | Web Development | Content of this section... | 2 |
| 3 | 0 | Contact Us | Content of this section... | 3 |
| 4 | 2 | Macromedia ColdFusion MX | Content of this section... | 1 |
| 5 | 2 | CSS | Content of this section... | 3 |
| 6 | 2 | HTML/XHTML | Content of this section... | 2 |
| 7 | 4 | Tags | Content of this section... | 1 |
| 8 | 4 | Functions | Content of this section... | 2 |
| 9 | 0 | About Us | Content of this section... | 4 |
Now, our dynamic sitemap should look like this (assuming that we order the content by WEIGHT) :
We will need to create two ColdFusion pages, "sitemap.cfm" and "getsitemap.cfm" as the following:
In this page, you just need to include the "getsitemap.cfm" as the following:
<cfinclude template="getsitemap.cfm">
This code helped me with alot of projects, I hope it helps you as well.
This was good then... but is there a better way now? Scott Offord
You should add weight to the select statement, e.g. SQL = "SELECT ID, PARENT_ID, TITLE, WEIGHT FROM request.menuQuery WHERE PARENT_ID = 0 ORDER BY WEIGHT"
Hi, I've got it working, but I only got an query error: ---------- Error Diagnostic Information Query Manipulation Error Code = 0 WEIGHT is not a column that can be sorted on. SQL = "SELECT ID, PARENT_ID, TITLE FROM request.menuQuery WHERE PARENT_ID = 0 ORDER BY WEIGHT" ----------- If I comment the "order by" out, then it's working fine. But actually I want the order function. Any help/suggestion? Nils
Thanks. Scott Offord.
this doesn't make much sense. i wish these tutorials had comments after every line explaining each variable and the purpose of each line. i would like to have a menu system for a cms but its hard wrapping my head around the logic behind it. why are you prefixing those variables with attributes. anyway?