logo

$25
Automatic list of child links on parent page

My WP site is here.

My parent page “Directory” is here.

I want the “Directory” page to automatically include links to all the child pages as shown in the right hand side bar,

i.e.
• Airfield Pavements
• Asphalt Modifiers and Binders
• Asphalt Technology
• Etc.

I have looked at various posts on forums, for example:

http://wordpress.org/support/topic/337703 and
http://codex.wordpress.org/Template_Tags/wp_list_pages#List_Sub-Pages

But whenever I attempt to put any of that code into my Page via the HTML tab, the resulting page just shows the code.

Do I need to install a plugin like Exec-PHP to enable code to be executed?

Regards,
Leigh

Leigh Wardle | 07/21/10 at 8:06pm | Edit


(3) Possible Answers Submitted...

  • avatar
    Last edited:
    07/21/10
    8:19pm
    Lew Ayotte says:

    Yeah, you can't use the HTML tab in the page to do this... you'll either need to add the code into the page.php theme file or install the php code widget (http://wordpress.org/extend/plugins/php-code-widget/) and use the widget for the sidebar.

    I like PHP Code widget better than Exec-PHP, just a personal preference.

    Do you need help generating the php code?

    EDIT: Also, depending on your theme (and your desire), you could put the code in the sidebar.php filel

    Previous versions of this answer: 07/21/10 at 8:19pm

    • 07/21/10 8:26pm

      Leigh Wardle says:

      Hi Lew,

      On your advice I will try the PHP Code widget.

      But how do get that widget working on the my parent page “Directory”?

      P.S. I do not want to change my sidebar - I am happy with it as it is.

      Regards,
      Leigh

    • 07/21/10 8:42pm

      Lew Ayotte says:

      WJM's solution will probably be the best for what you need.

      Lew

  • avatar
    Last edited:
    07/21/10
    11:41pm
    wjm says:

    Hi Leigh,

    There are three possible ways i can think of.

    1) install Exec PHP and include the php code in the content of the page.

    2) add a filter to the_content() to that page. I can write the code if you want this solution.

    or

    3) create a template and apply it to that page. Which is the one i recommend
    I have created this tempalte using page.php (from twentyten, the default wordpress theme), but you can create your own copying and pasting the code.

    save the following file
    http://wordpress.pastebin.com/dLp5XpYy
    as subpages.php and save it in your theme directory.

    Then go and edit the directory page in wp-admin, and on the right side bar, in the "Page Attributes" box, under "Template" select the tempalte "List Subpages"

    I dont know what theme you are using, but you can just make a copy of page.php and rename it subpages.php, and right after "the_content()" put this code


    <?php
    //LIST SUBPAGES [START]
    echo '<ul class="xoxo pages">';
    wp_list_pages( array( 'title_li' => false, 'parent' => $post->ID ) );
    echo '</ul><!-- .xoxo .pages -->';
    //LIST SUBPAGES [END]
    ?>



    I recommend using the tempaltes because you can apply it to how many pages you want, and using a filter, you will have to edit your functions.php file every time you want to add this feature to a new page.

    let me know if it works, and if you have any further question

    -wjm

    • 07/21/10 9:05pm

      Leigh Wardle says:

      Hi wjm,

      I am implementing your 3rd. option.

      I have saved the following file
      http://wordpress.pastebin.com/dLp5XpYy
      as subpages.php and saved it to my theme directory.

      But when I edit the directory page in wp-admin, in the "Page Attributes" box, under "Template", there is no template "List Subpages", only the 3 standard choices.

      Regards,
      Leigh

    • 07/21/10 9:19pm

      wjm says:

      try removing,

       * @package WordPress
      * @subpackage Twenty_Ten
      * @since Twenty Ten 1.0


      I am looking into it,
      which WordPress version are you running?

    • 07/21/10 9:22pm

      wjm says:

      better, do this,

      remove all the initial comments, and leave

      /*
      * Template Name: ListSubpages
      */

    • 07/21/10 10:51pm

      wjm says:

      Leight:
      Done

      the problem was that when i said save subpages.php to your theme's folder, i meant to to themes/YOURTHEMENAME/ folder.

      so i moved it to
      /wp-content/themes/neuticaplus/

      also, i used thematic's page.php as the base for this template. so it looks the same as any other page.

    • 07/21/10 11:17pm

      wjm says:

      And to keep the openess of this site:

      if anybody else wants this template, here's the template for Thematic.
      http://wordpress.pastebin.com/QR28D2GW

  • avatar
    Last edited:
    07/21/10
    9:58pm
    Pippin Williamson says:

    Use this plugin:

    http://wordpress.org/extend/plugins/list-pages-shortcode/

    It should do everything you need. Place the [child-pages] shortcode into a text widget.

    • 07/21/10 10:27pm

      Leigh Wardle says:

      Hi Pippin,

      I just put [child-pages depth="1"] in the Page content and here is what I get.

      It looks good to me - is that what I should be expecting?

      Regards,
      Leigh

    • 07/21/10 10:55pm

      Pippin Williamson says:

      Leigh, that's exactly what it was supposed to do. You may also put the list in the side bar if you wish by placing [child-pages depth="1"] inside of a text widget to display the child pages of which ever page you are on. Or, do as you have done and enter the shortcode directly into each page you wish to list the cild pages.

      If you're interested, for a small amount more, I can show you how to create another custom sidebar that would allow you to place widgets into the main-body of your pages, allowing you to list the child pages with the shortcode through a widget so that you don't have to enter manually put the short code into each page.

This question has expired.





Current status of this question: Completed