How do I represent ‘chunks’ of content within WordPress?

I’ve only ever used wordpress as a self-hosted blogging platform – until now. I have a requirement to use it for a very basic CMS which will consist of ~ 10 pages, most of which will be static content, updated periodically. I’m going to need to ability to upload documents, embed images, edit copy using the text editor – pretty much all of the standard features wordpress offers.

However, I’m having difficulty surrounding the issue of editing specific sections within a page – in particular, just knowing where to begin. A ‘normal’ CMS would traditionally break a page into separate sections and allow me to edit any of those sections, either by directly editing the content, or by including shared content in that spot. I cannot find out how to do this using wordpress.

Is it possible to ‘stretch’ the Page model so that a Page is actually just a chunk of content, it gets included by a specific page/template, and it’s – somehow – protected from being viewed directly (removing it from navigation menus being a start).

Any pointers on where to begin?

Update

To clarify, imagine a standard wordpress blog post. Pretend it’s a static piece of content. Suppose you wanted an editor to be able to change just the first paragraph of that blog post. Now,

  • should the static content on that page be in a Post, Page, Template, or something else?
  • should the editable content be a Page, … or something else?

For example:

<h1>About us</h1>

<p>Example.com is a company specialising in examples, demonstrations,
and canonical stuff.</p>

If I want that paragraph to be editable, presumably I need something like:

<h1>About us</h1>

<p><?php insert_page('name-of-content-chunk'); ?></p>

Update 2

OK, after a lot of research, trial, and error, I’ve included the following:

  1. WordPress is not set up to easily replicate a classic CMS, particularly with regard to having several pieces of content on one page.
  2. This model can be imitated, more or less, using custom posts (see below)
  3. Pages very nearly offer the ability to do this, however:
    • A plugin is required just to include a page
    • Pages don’t seem to be as flexible as posts – e.g. no custom page types

The method I’ve used, using custom post types, is broadly as follows:

  1. The page is a ‘Page’ with a custom template – call it ‘mypage.php’
  2. That template contains the following:
    <div id="header">
      <?php
        query_posts(array('name' => 'foo', 'post_type' => 'header-text'));
        get_template_part('header-text');
      ?>
    </div>
    
    <div id="content">
      <p>Some static copy in the template that can
      only be changed by the site administrator.</p>
    
      <?php
        query_posts(array('name' => 'bar', 'post_type' => 'image'));
        get_template_part('image');
      ?>
    </div>
    

Does that make sense to anyone out there? 🙂

5 s
5

As tnorthcutt mentioned, you may want to use custom post types. However, you should also take a look at custom fields, which will allow you to specify bits of dynamic custom data that you want to associate with each page. Here’s Smashing Magazine’s tutorial on custom fields, Nettuts’ tuturial (and video), and a list of other tutorials.

Leave a Comment