Content Management System

This tutorial covers how to write a web content management system using PHP. This WCMS (Web Content Management System) will function like Drupal or Joomla.
After you read this, then you'll be able to begin to start programming some CMS software using PHP. (⚆_⚆) Sounds like a whole heap of fun doesn't it? o_O

Content Management System Using PHP

A good content management system provides a service which will modify the way you manage your web page. If you have the time, the best method is to program a custom WCMS. If you do that, then you be able to modify it quickly.

If you like, you can also use the ready-made content management system packages like Drupal or Joomla. Many web-pages run on Drupal, for example, and it is generally found to be stable piece of software. You might find it useful. However, you might also see that the limitations of using a ready-made content management system package lead to issues with your web page management strategies.

You should make sure that your web page host is prepared to support the PHP version you are working with. You also need to ensure that they have a useful level of web hosting expertise. You might have to spend a great deal of time searching for an experienced PHP web host.

You should try all the primary web hosts. The primary significant web hosts are held to be BlueHost, 1&1, GoDaddy, and HostGator. The best strategy is to look closely at each offering, as it relates to PHP version and MySQL DB limitations.

Content Management System Programming

When it comes to content management system programming, you need a code base to start off of. Therefore, you should look at the following code. It is currently being used for a custom content management system in a production environment.

This code will help you to develop your custom WCMS package by giving you an idea of the source code necessary for custom WCMS programming. This sample code I wrote, which is currently powering my production custom content management system, is based on resources off the web.

What You Are Doing with This Code Is the Following:

1. You use the first sentence of the entry as a title for the entry.

2. After that you list all the entries, using the first sentence of each entry as the entry title.

3. You might find this is an excellent way to organize your app, as it will automatically update the title database entry.

4. When it comes to a WCMS, there is no reason to have a title field in the database which doesn't update.

These titles also update right away when you modify the entry. Therefore, you don't have change a separate database field if you modify your listing.

The code which separates out the first sentence in the entry is in this part.

"<?php $entry_array = explode('.', $entry->content); ?>"

What this does is make an array using all the sentences found in the $entry->content string. The first string found in this array will be the first sentence in the entry.

So when we use the next line:

<?php echo ($entry_array[0])."."?>

You are grabbing the first string in the entry array ($entry_array[0]), which has the first sentence in the entry.

With the next line, you are showing the rest of the entry. You do that by selecting the entry string using the substr command.

<p><?php echo substr($entry->content, strlen($entry_array[0])+1)?></a></p></li>

You begin with the start of the string as the character which is found one character after the end of the first sentence or:

strlen($entry_array[0])+1)

Full Code

<?php include "includes/header.php" ?>

<div class="cache">

<h1>JOURNAL</h1>

<ul id="headlines">

<?php foreach ( $results['entries'] as $entry ) { ?>

<?php $entry_array = explode('.', $entry->content); ?>

<li><p><b><?php echo ($entry_array[0])."."?></b></p>

<p><?php echo substr($entry->content, strlen($entry_array[0])+1)?></a></p></li>

<?php } ?>

</ul>

</div>

<?php include "includes/footer.php" ?>

WCMS Software

You should look at developing your WCMS software, as it will give you the functionality you want. This code example will provide you with a code base to start off of. You may have to invest in programming the initial software package. However, you will save a great deal of time during the maintenance phase of using the software. That is statistically the most expensive phase of software use.

You may be tempted to use a ready-made package such as Joomla, Drupal, or something of that nature. However, you will see that the limitations of using a one-size-fits-all solution will make it more difficult for you to achieve the functionality you want. The time you invest in developing your software package will pay off in the future.

About the Author
About the Author Image

Gerard I. "G.I." Prud'Homme M.Sc.

has studied at Harvard, Oxford, and the University of London and has lived in London, Paris, Hawai'i, and Los Angeles. He has a Master of Science in Computer Science degree, is fluent in many programming and human languages, and has programmed several shareware, freeware, and open-source programs. He has also had a dozen books published. He now works as a Developer and lives in CA in the Greater Los Angeles region.