A Monthly Web Magazine Using WordPress

The Editor’s Problem

WordPress does what it does well.  It’s almost intuitive when it comes to writing posts and pages.  Suppose though, you are an editor for a monthly on-line magazine and  you need to display posts and pages in some ordered sequence.  Using the magazine metaphor for moment, you would like the ability for the writers to create pages and posts on-line and in any order.  You as the editor would like the ability to sort the content by section and maybe you might like to rearrange the content in various sequences or perhaps insert a page here or there as the editing process proceeds.  Perhaps you would like to compose an on-line technical manual or perhaps it’s a book of poems or favorite recipes.  WordPress and the its contributors have added some possible features to address this need.

A Step Towards A Solution

WordPress has had tags for posts from almost the beginning and there are content categories as well.  Pages have been the forgotten stepchild; they were perceived as not needing anything other than a title and perhaps a parent page to sequence to.  In order to add some filtering and sorting capability to pages,  a type of meta tag (custom fields) was added to pages.  Then for good measure custom fields were added to posts as well.

While Categories and Custom Fields provide a way to the solution,  there are several missing pieces.  One of the pieces is how to interrogate the data base.  The proposed index is a listing of all posts and pages with a tag or custom field equal to “some unique value” and after they are identified sort them according to some sequence.  The index should not care if the content is on a post or a page but should list them by sequence.   The sequence can be numbers,  letters,  dates, etc.  An allied problem would be content integrity – When a reader or reviewer  goes back into an archive to a particular issue,  he/she would like to be certain the data has not been modified over time.  This can happen if one of the referenced pieces is modified for use in some other document.  With WordPress there is a lot of commonality,  the header image can be updated, re-sized,  or the wording for the common footer may change for legal reasons or simply because it’s a new year.  This suggests that each issue  have a unique set of images, header code,  footer code and maybe sidebar menu code.  You can see that just keeping the pages in some sequence order is only part of the problem.

WordPress Behind the Scenes

Underneath it all are WordPress’s approximately 10  database(s) tables.   Intuitively, you might think the database is one large flat file.  In this case though, the tables are mostly pointers to some other table. The exact layout is unimportant except to realize that although pages are a special type of post, there are different program interfaces for the two and lots of tables to maintain the relationships.  Because WordPress has been around for  years and the user community is large,  there are lots of code snippets available use for almost any programming problem encountered.  I wanted to group all of the Android material under a common heading  Android Papers and there were posts and pages intermixed and on different dates.  Sometimes the later ones really needed to read before some of the earlier ones.  The overall solution was to create a template file that would gather links to posts and pages that had a common metatag or custom field as well as sequence key and then list their links in sequence.  When one of the links were clicked, the page/post would be displayed.  Additionally, there should be navigation links to previous page, next page,  and links back to the Android page or back to the Home page.  The template file  creates the directory page and an IFrame construct displays the clicked on link.  For those interested in the nuts and bolts of it all,  the next section has the source code and some WordPress references.

Source Code and References.

There two parts to the template file loop.  If a link is clicked,   the top part with the IFrame is executed and displays the page referenced by the link.  If nothing is returned the lower “create the  directory”  portion is executed.  The template file uses tags or custom fields where  volumeID = “Android” and seq=” some number”.

androidpapers This template can be referenced by any page to create a new directory.  Only the template name . custom fields, and tag refereences  need to be changed.  Change the file type to .php before using :-]

get_post_meta. This function returns the values of the custom fields with the specified key from the specified post.

childish_functions Read all pages and posts filtered by tag and meta name, returns an sorted array.

functions References  base_get_all_custom_fields so as to fetch all custom fields.