Using nanocms to create a simple site with news

For a client of mine i've been looking for a way to host his very simple and small site. The site (which can be found here in its old outfit) consists of some rather static pages, two formulas, which have to be sent by email and a news section that is split into two categories (events and tours). Both news categories land in a collective archive after a specific date.

Until now, the site has been using a selfmade content management system, which reads custom files in some directories. Every time i wanted to change the content of an event article, add a new one or move it to the archive i had to manually change the files. You have to have in mind, that the customer asked for a rather minimalistic server hosting solution and i didn't see it as necessary for him to have a database in the hosting package. The problem is that most content management systems are in need of a database of some sort (mostly mysql). Yes i am aware of plugins for cmss that can do the job. But mostly the systems are too complicated to setup for this simple site..

In come nanocms. Nanocms is being developed by Kalyan Chakravarthy who runs his own blog over at kalyanchakravarthy.net (last update about nanocms). From the description of the project:

Nano CMS is the tinyest CMS you can find around...:)
The user interface and the functionality are very very simple and easy to use.
NanoCMS is filebased, so no database blah,. Easy to install

Through this CMS you can create pages without actually touching any code.
You can manage website pages very easily and the links in the sidebar are generated automatically...

Indeed nanocms is really small and well written for that. The main functionality consists of creating pages, which are then stored in distinct files in a specific folder. The only way to sort the pages on the site is to include them in different categories (each page can be a member in different categories) and then using those categories for displaying menus. There is no way of specifying a hierarchy for the pages. The sort order of the pages inside each category though can be changed independently.

Now, this functionality doesn't provide exactly what i needed, since i wanted some "pages" (/posts) to be shown on the same webpage - like a blog. Also, i needed submenus to allow the navigation the client was asking for.

So, this is what i did..

To extend the functionality of nanocms i created "customfunctions.php" with the following two functions:

PHP:
  1. <?php
  2.  
  3. function show_contents($cat){
  4.     global $cap;
  5.     $itemlist = get_links_array($cat);
  6.     foreach( $itemlist as $slug=>$title ){
  7.         show_content($slug);
  8.         echo '<hr />';
  9.     }
  10. }
  11.  
  12. function show_content($slug){
  13.     $contentFile = pageDataDir( $slug );
  14.     if( file_exists( $contentFile ) ) {
  15.         runTweak( 'slug_load_before' );
  16.         require_once( $contentFile );
  17.         runTweak( 'slug_load_after' );
  18.     }
  19.     else {
  20.         header("HTTP/1.0 404 Not Found");
  21.         echo "404 : File Requested was Not Found";
  22.     }
  23. }
  24. ?>

The function "show_contents" is a near-copy of the native function "show_links" which shows all the links to the pages inside a category. "show_content" is a near-copy of "show_content_slug" with the only difference, that "show_content_slug" doesn't accept any argument and gets the page slug from the global variable $cap.

With those two functions i'm now able to show a page inside another page (which i use to display the "Kontakt"-page under the welcome message) and i'm able to show the content of a category.

So, the content of "Aktuelles" becomes the following small script:

PHP:
  1. <h2>Aktuelles</h2>
  2.  
  3. <?php show_contents('aktuelles'); ?>

And here is a link to the site, as i proposed it to the client: www.campuscultur.de/nano/

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>