There are two places I've found good code and ideas for dynamic web pages and content management systems (whichever term you prefer). One is
Jon Udell's Practical Internet Groupware. The other is the
Everything code. The latter runs this site.
You may not do things the same way, but if you study the code you'll find how people are making this work in the real world.