While building a web site, it is sometimes important to manage content pieces separately and independent of each other. Imagine a corporate site with a homepage that has briefs on its various offerings, and a brief about itself. Each of these briefs are managed independently, and the homepage is composed by integrating them together. How do we achieve this with WordPress?
One of the ways this can be done is to include the text in the theme file itself. But this means that you will have to ask the maintainer to modify the theme file to modify the content, which can be dangerous. Also, as a CMS developer, I would like the administrator to get a first hand way of managing this content, including a WYSIWYG editor if they are used to it. The first thought that came to my mind was to write a plugin, which I still think is the best solution to work with. However, I experimented with something else as well – using private pages to do this.
We can use a page for every piece of content we want to be managed independently. The only problem is that these pages are still visible to the WordPress loop. One way to avoid this is to make them private. We can then use the
get_page function to retrieve content from one of the private pages, which takes the page ID and returns the page to you. Or we can use
get_page_by_title where we can pass the page title to retrieve the page.
This will provide all the WordPress editing tools to the content editor/maintainer to modify these individual pieces of content. It will also give them a good admin backend to manage those pages themselves.
Having said that, there are certain disadvantages of this approach. Retrieving multiple pages to compose one page means more database hits. Secondly, by making the pages private, and hidden from the WordPress loop, we will not be able to use any of its utility functions, like
the_content. We will have to use
$page->post_content to retrieve the page content in our template. Though this is not difficult, functions other than the template tags can change in future releses.
A plugin might be the real solution here, though using the pages differently was quite interesting, and might turn out to be useful in some cases. What do you think?