Daniel M. Hendricks

Template – Page Tree

Source code hierarchy example in WordPress

Last updated: 12/14/2008

This is a custom page template that displays a list of child pages.

Example

This template is most useful when you have pages that list links to other pages.  For example, on my own web site, I have the Source Code page, which links to specific languages like ASP.NET and PHP, which then link to specific articles like this one.

The Source Code, ASP.NET and PHP pages all make use of this template (called pagetree.php), whereas the actual articles use the standard page.php template (ie, ‘Default Template’ in WordPress).  The pagetree template simply lists child pages below the current page.

See the image to the right to see an example of how my Source Code section is set up, and which template each page is associated with.

Installation

Installation is easy – simply copy the pagetree.php file to your theme(s) template folder.

Usage

Once you have installed the file, you can use it in WordPress.  As an example, create a new Page in WordPress with a title of “Restaurant Reviews”.  You can leave the body content of the page blank if you wish, or you can enter some content to appear at the top of the page.

Next, from the Template dropdown, select “Page Tree” from the list.  Click Publish.

Now, create some child pages with “Restaurant Reviews” as the Parent page.  These pages will have the Template left at “Default Template”.

Once you create the child pages, you should be able to navigate to/view the parent “Restaurant Reviews” page and you should see a clickable list of all the child pages!

Download

View source: pagetree.php

Post a Comment

You must be logged in to post a comment.

Tip: Sign up for a free Gravatar to have a photo next to your comment! Your gravatar will follow you around when you post to blogs that support it, based on the e-mail address you use to post.