Child Pages

When to use

When you need a quick and effective way to display a list of links to all pages that are children of the current page.

NOTE: This shortcode will only work on the parent page to display children of that page.

Basic Usage:

[childpages]

Add [childpages] to the location on the page where you would like to display a list of links to all child pages of the current page/directory.

Results

Child Pages

Simply adding the shortcode:
[childpages]
will generate a header “Child Pages” and a an unordered list of links to all childpages as in the example above.

If you would prefer to use your own heading (instead of the text Child Pages) before the list, include the attribute heading=”Your Heading Here”, e.g. [childpages heading="Your Heading Here"]

A Typical Use Case

This shortcode was originally created to address a peculiarity of WordPress directories — see below for details. Therefore, it will often be used when a new directory is created. In WordPress a directory is created when you assign a page a parent page. Once a page has child pages, the shortcode can be used.

  1. Write the shortcode on a page that you want to use as parent page
  2. Make sure that the child pages are assigned the correct page in the attribute of “Parent”
  3. The code will automatically display a list of links to all pages which have the present page as a Parent

Understanding Directories in WordPress

Typically, when we think of directories in the context of computers and software we think about the folders in the computer that allow us to organize files, as well as sub folders.In WordPress there is no formal directory structure in the strict sense of the word. So what does it mean to have parent and childpages?

The parent-child relationship in WordPress is assigned using the dropdown menu Page Attributes > Parent on the right pane of the edit page. This Parent attribute is an attemp to mimic a directory structure. It works very similar to a directory, with some exceptions.

When a page is assigned as a parent of another page it doesn’t cease being a page to become a directory. The parent page looks just like any other page, however, now it becomes possible to nest the slug — URL path — to show the relationshionship. For example:

www.library.illinois.edu/example-directory/example-child-page

In the example above example-directory is, structurally, as much of a page as is example-child-page. However, we can see a hierarchical relationship between the two in the URL. During the migration from OpenCMS to WordPress, for instance, it was necessary to create directory pages using this method in order to mimic the old URL paths as closely as possible, because this allows the system to redirect from the old URL to the new one. This means that you may see a page which contains only the [childpages] shortcode. More than likely that means that the page is a directory page, and would normally be completely empty, however, the shortcode allows us to use the empty directory page to show a list of the pages contained within it.