How to Show Child Pages in a WordPress Blog

WordPress uses a "parent" and "child" heirarchy to organize pages into main pages and sub-pages. When you make a page a "child" of another page, than that other page becomes its parent. You can add code to your "page.php" template to display a list of child pages on parent pages. This code relies on the "wp_list_pages()" function and uses the "child_of" setting. As long as you tell the function to look for the ID of the current page, WordPress will output the correct child pages for each parent page.

Instructions

    • 1

      Log in to WordPress and navigate to "Appearance." Click the "Editor" link and locate the "page.php" file listed under "Templates." Open that file by clicking its link.

    • 2

      Locate the portion of the page where you want to display the child pages. Add a pair of "<ul>" or "<ol>" tags and place the "wp_list_pages()" function between them:

      <ul>

      <?php wp_list_pages(); ?>

      </ul>

    • 3

      Pass some arguments in to the "wp_list_pages()" function to tell it which pages to list. Because you want to list child pages, use "child_of" and set it to "$post->ID" to get all children attached to the ID of the parent page:

      wp_list_pages('child_of='.$post->ID);

Tips & Warnings

  • Mistakes in PHP code will cause your blog to display "white screen" errors. Back up your theme files before editing them so you can re-upload the files in the event of a PHP error.

Related Searches:

References

Comments

Related Ads

Featured