Home arrow PHP arrow Page 5 - Building a Relational Content Management System in PHP/MySQL

Displaying the Articles - PHP

You may be familiar with relational databases, but what is a relational content management system? Read on to learn how to build this system, which helps you create a search engine friendly site fairly quickly.

TABLE OF CONTENTS:
  1. Building a Relational Content Management System in PHP/MySQL
  2. The Rewrite
  3. The Common Functions
  4. Managing Articles
  5. Displaying the Articles
By: Roger Stringer
Rating: starstarstarstarstar / 39
December 20, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Okay, so now we've reached the fun part, actually displaying the articles for people to read.

Create a file called "index.php":

<?
  include("common.php");
  $mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
  $seoname = isset($_REQUEST['seoname']) ? $_REQUEST
['seoname'] : '';
  if( !empty($seoname) ){
    $seoname = explode("-",$seoname);
    $seoname = end($seoname);
  }
?>
<table width=100%>
<tr>
  <td width=200>
<?
  $leftMenu = getPages('parent','0');
  foreach($leftMenu as $id=>$page){
    echo "<a href='{$page['seoname']}.html'>{$page['title']}
</a><br/>";
  }
?>
  </td>
  <td>
<?
  if( !empty($seoname) ){
    $page = getPage('seoname',$seoname);
  }else{
    $page = getPage('id','1');
  }
?>
    <h1><?=$page['title']?></h1>
    <p><?=nl2br($page['body'])?></p>
<?
  $kids = getPages('parent',$page['id']);
  if( count($kids) > 0 ){
    foreach($kids as $id=>$kid){
      echo "<a href='{$page['seoname']}-{$kid['seoname']}.html'>
{$kid['title']}</a><br/>";
      echo "<p>{$kid['summary']}</p>";
    }
  }
?>
  </td>
</tr>
</table>

Here, we look to see whether we've passed the $seoname variable, and if we have, we split it into an array and grab its last value. This lets us use that as the article id and display the current article. We can build on this system quite easily.

Conclusion

There we have it: a quick, easy to use Relational CMS.

This CMS can be built on pretty easily and quickly, but I wanted to get the basics down here first.



 
 
>>> More PHP Articles          >>> More By Roger Stringer
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap

Dev Shed Tutorial Topics: