Building a Relational Content Management System in PHP/MySQL - Displaying the Articles
(Page 5 of 5 )
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.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|