Support » Fixing WordPress » How To List a Page’s Subpages Within that Page

  • Resolved chanel

    (@chanel)


    I created a page (using the Write Page feature) called “Writings” and I would like to list all of the subpages FOR that subpage by using a code, rather than manually typing out the page titles and linking them to the pages i created. Is there a php code (i guess similiar to wp_list_pages) that i can use to create this?

    Here an example of what I’ve done, however, I prefer to just use a code to call all the subpages I created for this instead of doing it manually:
    kisschanel.com – Writings

    I’m not familiar with php, other than what I know from trial and error, so it’ll be great if someone can leave a detailed explanation on how to do this.

    Thanks in advance.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Add

    <?php wp_list_pages('child_of=1'); ?>

    to the page, where “1” is the post ID of your parent page.
    From here: http://codex.wordpress.org/wp_list_pages

    Cheers

    Hi nublooo. That didn’t work for me. Take a look:

    http://chanellie.com/index.php?page_id=8

    I tried posting that same code in Visual and then in HTML and nothing still shows. Am I doing something wrong?

    umm… you add the code inside your page.php not on Write > Page area. good luck.

    Ok mercime. As you can see, and I stated before, i am NOT a php guru. I also did that however and nothing shows up. Here is my page.php source:

    <?php get_header(); ?>
    <div id=”main”>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class=”post”>
    <div class=”post-title”><img src=”http://kisschanel.com/hearts.jpg” style=”float:left” alt=”” /> ” style=”text-decoration:none;” rel=”bookmark” title=”Permanent Link: <?php the_title(); ?>”><?php the_ttftitle(); ?>
    </div>

    <div class=”entrytext”>

    <?php wp_list_pages(‘child_of=1’); ?>

    <div align=”justify”><?php the_content(‘<p class=”serif”>Read the rest of this page »</p>’); ?></div>

    <?php link_pages(‘<p>Pages: ‘, ‘</p>’, ‘number’); ?>

    </div>
    </div>
    <?php endwhile; endif; ?>

    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    <img src=”http://chanellie.com/footer.jpg” alt=”” />
    </div>

    According to your link above your page ID is “8” so change :

    <?php wp_list_pages(‘child_of=1’); ?>
    to
    <?php wp_list_pages(‘child_of=8’); ?>

    Pirazo!! Thank you for the help sweetie! That worked.

    I’ve been sitting here for 2 hours trying to figure that out. It’s so hard to read php when you don’t understand it. Thanks again to everyone for their help.

    Ok I thought this was resolved but it’s not.

    Now when I go to any of my pages, the list of the subpages for the “Writings” section are loading in each one. How can I prevent that from happening? I only want the subpages to be listed in ONE subpage.

    Example: http://chanellie.com/index.php?page_id=14

    Hi Chanel,

    If I understand it correctly, you have one parent page “Writing” and on that you’d like to list all of your writings which are subpages.

    To do that, you first need to create a page template which is separate from the default template every other page uses.

    It’s as easy as simply making a copy of page.php and calling it page_writings.php.

    Now you need to first remove the line of code you added above from the page.php, but leave it in your new page_writings.php.

    Then you need to tell WordPress that your newly created page_writings.php is actually a page template – you do that by editing it and before anything else, first thing on the page, you paste this code:

    <?php
    /*
    Template Name: Writings
    */
    ?>

    Save the file and upload it to the same folder as all your other theme’s files, along with the also edited page.php (without the line of code above).

    The only thing left to do now is tell WordPress to use your new template for the specific pages you want the subpage listing to appear on: In your Admin area, go to “edit page” and way down, under the editor box, there is a box called “Page Template”. If you did all of the above right, your new page template “Writings” should appear there – select it, save, and you’re done.

    If you want that subpage listing to appear on your subpages as well, you must go into each one and select this template for them as well.

    Hope this helps!

    Ok, let me try that right now and tell you the results in a moment. Thsnks for the quick response also nublooo.

    Yes!!!! That works!!! Thank you so much nubloo 🙂

    Quick Question : How can I get rid of the word “Pages” and put my own statement?

    Very good!

    To change the heading, replace the above code with the following:

    <?php wp_list_pages('child_of=8&title_li=<h2>' . __('Mytitle') . '</h2>'); ?>

    …and change Mytitle to your preferred heading. That should do it 🙂

    Yes, got it. Thanks again nublooo. I appreciate your patience!

    wow nublooo you really helped her. But i am having the same problem as you are having..

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘How To List a Page’s Subpages Within that Page’ is closed to new replies.