Wordpress as a CMS

This tutorial is aimed at developers who just want wordpress to function as a lightweight CMS, that is wordpress will only be used for editing page content.

First install wordpress in whatever directory you want the admin to live. I chose /admin.

Any page that needs to use wordpress functionality you must add this:

require('/path/to/wp-blog-header.php');

This gives you access to wordpress functions that we need:

  • get_page – Get the page data from the database
  • wpautop – Automatically add paragraph tags to page content

To get page content:

$page_data = get_page( 4 ); // Where 4 is the page ID in wordpress

There is a bug in certain versions of php, if you get the error:

Fatal error: Only variables can be passed by reference…

Then use this format instead:

$page_id = 4;
$page_data = get_page( $page_id );

$page_data now contains all of the info for that page, and is ready for use in your templates/views. Check the function reference to see the data you have available to you.

To display post_content use the wp function wpautop.

<?= wpautop($page_data->post_content) ?>

It’s simple!

Tags: ,

Leave a Reply

You must be logged in to post a comment.