• View our reviews on Hot Scripts
  • JS Tutorial

Recent Comments

Powered by Disqus

Back to articles

Simple Auto-CMS using HTML pages

Here is an interesting idea of CMS which is managed by HTML files. It is simple php script, that searches specified location and takes all folders and html files and interprets them as pages and content. Basically, you can manage your content with HTML files, and this script will automatically create menu to browse them.

For example, this script looks in the content folder. If there is an HTML file named index.hmtl, it will be outputted as content, if there are any other HTML files, links in menu will be created for them. Folder with HTML files is like a submenu, and folder inside folder - subsubmenu.

So if you have structure in content directory like index.html, contacts.html, folder works, which has index.html and myworks.html, then menu contacts with submenu works, which will include myworks will be automatically created. 

Here is an example of how it works:

And here is a php code snippet:

    <title>Some titile</title> 
    <!-- you can use styles -->
    <link rel='stylesheet' type='text/css' href='/style.css' />  
    <div id='header'>  
      <h1>Website title</h1>  
  // Get the path  
    $a = $_GET["a"];  
    $a = "";  
  $path = explode("/", $a);  
  $current_path = "";  
  // Create the menu   
  echo "<div id='menu'>n";             
  for($i = 0; $i < count($path); $i++)  
    $contents = scandir("content/".$current_path);  
    echo "<ul>n";  
    for($j = 2; $j < count($contents); $j++)  
      // Do not create a link if its called index.htm, this will be open automatically  
      if($contents[$j] != "index.htm" && $contents[$j] != "index.html")  
        // This makes it so the active links are a different color  
        if($contents[$j] == $path[$i])  
          $li_class = " class='open'";  
          $li_class = "";  
        $this_path = $current_path.$contents[$j];  
          $this_path = $this_path."/";  
        // The actual link  
        echo "<li".$li_class."><a href='/".$this_path."'>"
    echo "</ul>n";  
    $current_path = $current_path.$path[$i]."/";  
  echo "</div>n";  
  // Render the content  
  echo "<div id='content'>n";  
  $file = "content/".$a;  
    $ext = substr($file, strrpos($file, "."));  
      // If the file is a html file, just copy it  
      case ".htm":  
        $foo = file_get_contents($file);  
        echo $foo."n";  
      // All other files get a download link  
        echo "Download <a href='".$file."'>".$file."</a><br >n";  
    // If a folder is selected, and it contains an index.htm file, render it  
      $foo = file_get_contents($file."index.htm");  
      echo $foo."n";  
    else if(file_exists($file."index.html"))  
        $foo = file_get_contents($file."index.html");  
        echo $foo."n";  
  echo "</div>n";  

  <div id="footer">  
    Footer credits 

And here is a mod rewrite to put in .htaccess file for search engine friendly URLs:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.+)$ /index.php?a=$1 [L]

You may also be interested in:

Powered by

blog comments powered by Disqus