Introducing the Bookworm plugin

If you are familiar with Drupal, you are probably familiar with the concept of a “book”. A Drupal “book” is a collection of Web pages that are automatically tied together with proper hyperlinks, so that there is no need to build navigation manually.  There is typically a table-of-contents page and a number of chapter pages.  Recently, I needed to build a few “books” in WordPress, so I ended up writing a little plugin that I called Bookworm.

The data organization in WordPress allows to build “books” rather easily. WordPress pages are hierarchical, so it is possible to create any number of chapter pages to which the table-of-contents page would be a parent.  So all you need is a way to automatically generate a table of contents (essentially, a linked list of the current page’s children) and a a way to automatically build a navigation menu with links to previous chapter page, table of contents, and next chapter page.

Enter the Bookworm plugin.

Put [bookworm_list_pages] into the table-of-contents page, and it will output a list of pages which list the current page as their parent.  For now, pages can be listed only in order of their ID (which, conveniently, is also the order in which they were created).  Putting [bookworm_flip_pages] into a chapter page will output hyperlinks to previous chapter, table of contents (which is assumed to be on the parent page), and next chapter.

Leave a Reply

Your email address will not be published. Required fields are marked *