WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Dynamic lists of subpages? (5 posts)

  1. michammel
    Member
    Posted 9 years ago #

    I want to have the actual page to show the subpages (if any) as a submenu
    Eventhough the_ID is supposed to work only in the Loop, it can display the ID all over the place, but why does this not work?
    <?php wp_list_pages('child_of=the_ID&title_li= '); ?>

  2. skippy
    Member
    Posted 9 years ago #

    If you copy-and-pasted that directly from your template, it won't work because the_ID is a function, and would need to be called as such:
    <?php wp_list_pages('child_of=' . the_ID() . '&title_li= '); ?>

    That won't work, though, because the_ID() directly outputs the ID to the browser, rather than return it for use in your program:
    function the_ID() {
    global $id;
    echo $id;
    }

    So, you'll need to try something like:
    $ID = $wp_query->post->ID;
    wp_list_pages("child_of=$ID'&title_li= ');

  3. michammel
    Member
    Posted 9 years ago #

    Thanks Skippy for the explanation of the_IDfunction, and for putting me on the right path.
    Your fix didnt work right away but after some tinkering with it, I made it work:
    The solution is
    <?php $side = $wp_query->post->ID;
    wp_list_pages("child_of=$side".'&'.'title_li= ');?>

    It could probably be more elegant, but it works.

  4. nearlythere
    Member
    Posted 8 years ago #

    looks like you have a solution, i've tried it out and it works well.

    i am using another smippet which does the same thing in my sidebar to get subpages to appear:

    <?php
    global $id;
    wp_list_pages('child_of=' . $id . '&title_li=<h2>' . __('In this section') . '</h2>' );
    ?>

    my main problem with both is that NEITHER work on the subpages themselves- meaning they don't display 'sibling' pages; and i want to use this to make a persistent menu.

    btw- i've seen the folding pages plugin, but i don't want a collapsing menu.

    any simpler options that i'm overlooking?

  5. nearlythere
    Member
    Posted 8 years ago #

    answering back to the me i was a few hours ago:

    you make new file (for example sidebar-page3.php) to be a custom sidebar, calling a specific ID number, like this:

    <?php
    wp_list_pages('child_of=3&title_li=<h2>' . __('In this section') . '</h2>' );
    ?>

    then include this in a custom template, instead of the regular sidebar:
    <?php include ('sidebar-page3.php'); ?>

    seems tedious, but it can work.

Topic Closed

This topic has been closed to new replies.

About this Topic