WordPress.org

Ready to get started?Download WordPress

Forums

List sub pages inside a page... hmmm :) (4 posts)

  1. mreddy
    Member
    Posted 7 years ago #

    I would like to list the sub pages inside a page. I am using runPHP to run php inside my page... For some reason this piece of script returns "4" ?!?!

    <?php
    $current_page_id = the_ID();
    wp_list_pages("child_of=$current_page_id");
    ?>

  2. maerk
    Member
    Posted 7 years ago #

    the_ID() doesn't return the ID for use in PHP, it inserts it into the page, which is why it's showing up.

    Try this:

    wp_list_pages("child_of=$id");

    and if that doesn't work and the following just before it:

    global $id;

  3. phoenix9bird
    Member
    Posted 7 years ago #

    where do u put this code?? has it worked yet??

    i too want to show my sub pages in my parent page..

  4. oliviameiring
    Member
    Posted 6 years ago #

    this code works perfectly, and unlike a lot of code floating around the support forums, it also displays the submenu when you're on child page:

    <ul>
    <?php if(get_the_title($post->post_parent) != the_title(' ' , ' ',false)) {
    	wp_list_pages("child_of=".$post->post_parent."&sort_column=menu_order&title_li=");
    
    } else {
    
    	wp_list_pages("child_of=".$post->ID."&sort_column=menu_order&title_li=");
    }
    
    ?>
    </ul>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.