and like us on FB

When you publish a page in WordPress, you have the option of selecting a parent page. All pages underneath that page become child pages – essentially creating a subset of pages (attached to a topic). The WordPress shortcode and plugin as described in this article will permit you to render all page results attached to a parent page in a list. See examples on our code page and reference page. While we’ve provided a few of these types of shortcode in the past, they’ll all be rewritten so the code is a little closer to WordPress best practice.

The Result

As linked to above, the shortcode will list pages attached to a parent page (or a page as defined in your shortcode). As an example, the shortcode of [childpages page="12345" description="false"] will return the list as rendered below (where ‘12345‘ is your parent page). If the page attribute is not used, the current page will be used as the parent page. I’ve used description="0" to prevent the excerpt from printing.

As stated above, a better example with the excerpt might be on our code or reference page.

Shortcode Attributes

The following shortcode attributes may be used. We’ll add more options in the future so make sure you subscribe to us on Facebook for updates.

page

By default, the current page will be used. To list the child pages of another page, use page="12345" where 12345 is that page ID.

remove

The remove attribute is used to remove a string of text to be omitted from your excerpt. In our case, we use it to remove the tweet text and Facebook that’s rendered by default with our post. So, we use remove="Tweet  and like us on FB ".

description

The excerpt will print by default. To silence it, use description="0".

words

The words attribute relates to the number of words in your excerpt. To limit your excerpt to 20 words, use words="20".

exclude

To omit certain pages from your results, use exclude="20,21,22,23" (a comma-delimited list of page IDs to be left out).

WordPress Shortcode

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

Considerations

  • Read more on wp_query here .
  • We’ll likely develop this into a more robust plugin with pagination and other features. So, the plugin option isn’t entirely unreasonable (we’ll let you know when the update is available).

Download

Title: Display a List of Child Pages With WordPress Shortcode
Description: Display a List of Child Pages With WordPress Shortcode.
Download: Shortcode (V0.1) | WP Plugin (V0.1) | | Plugin Page

Shortt URL for this post: http://shor.tt/2FO1