WordPress.org

Ready to get started?Download WordPress

Forums

wp_list_pages (7 posts)

  1. measureyougive
    Member
    Posted 5 years ago #

    I was reading about wp_list_pages here: http://codex.wordpress.org/Template_Tags/wp_list_pages

    and attempted to use the following suggested code to display subpages of the current page:

    <ul>
      <?php
      wp_list_pages('title_li=&child_of='.$post->ID.'&show_date=modified
      &date_format=$date_format'); ?>
      </ul>

    The information about wp_list_pages doesn't say where to use this code, so I assumed it could just be pasted into any existing page, where I want the list of subpages to appear.

    Unfortunately, using the WYSIWYG editor included in WordPress doesn't seem to support this, because the page now just displays the code as is, (looking at "View Page Source" from Firefox shows that it replaced "<" with "<" and ">" with ">" etc...).

    Am I doing this incorrectly? Is it a bug with WordPress' WYSIWYG editor? a bug with Firefox?

    Thanks for any info!

    EDIT: I realized that the editor here changed my "& l t ;" and "& g t ;" above to the symbol I was trying to describe. Assume that the second < and the second > are their respective HTML code representations.

  2. whooami
    Member
    Posted 5 years ago #

    yes, you dont put template tags inside pages like that. template tags go inside template files. wp_list_pages is a template tag.

  3. measureyougive
    Member
    Posted 5 years ago #

    ah, hehe, hence the name "template tag"

    so how might I accomplish this? If I create a bunch of pages that are sub pages of another page. is there an easy way to automatically create a list of these sub-pages within the parent page?

  4. whooami
    Member
    Posted 5 years ago #

    so how might I accomplish this?

    youre on the right track with using that bit of code.. you just need to put it in the right place

    why dont you just use a widget to list your pages?

    http://www.arnoldbreukhoven.nl/2007/03/breukies-pages-widget-for-wordpress/

    or maybe this one?..

    http://wordpress.org/extend/plugins/flexi-pages-widget/

  5. measureyougive
    Member
    Posted 5 years ago #

    unfortunately, I don't want these sub-pages listed globally in a widget... (from my understanding, widgets get put in the sidebar, which is loaded on every page).

    I would like the list of sub-pages to appear in-line on their parent page.

    For example, imagine that I have a page called "Camping" that will be the parent page, and many subpages about specific camping trips that I have gone on.

    I put a brief paragraph on the parent page that I love camping and will list each of my camping trips below. And then I want to use the functionality of wp_list_pages to list all of the subpages so that people can reference this as a running list of all my camping trips, and they should be able to click the title of each listed page to be directed to a subpage with details about that particular trip.

    I understand that this is apparently a complicated thing that wordpress isn't designed to do... at least not out of the box. I am reading about page templates and hope to be able to create a custom template that will do this...

  6. measureyougive
    Member
    Posted 5 years ago #

    Okay, problem solved... to anyone else that wants to do this... you can't quite do what I wanted because the list of subpages must be at the end of the parent page's normal content.

    Basically, I found the page.php template file, copied it as page_with_subpages.php and put this at the top of the file:

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

    Then I put this code immediately following the line with "the_content();"

    <ul>
    <?php
    wp_list_pages('title_li=&child_of='.$post->ID); ?>
    </ul>

    When you next edit a parent page that you want to list sub-pages of this parent, you can select this custom template as that page's default template.

  7. kove
    Member
    Posted 5 years ago #

    MAN I love YOU.

    Seriously.

    I tried to figure out why wp_list_pages() didnt work for MONTHS and now IT WORKS!

    thanks a lot and excuse me for the excitement, but you solved me a GREAT problem.

    thank you again.

Topic Closed

This topic has been closed to new replies.

About this Topic