Support » Fixing WordPress » Dynamic lists of subpages?

  • Resolved michammel


    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= '); ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • skippy



    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= ');

    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.

    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:

    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?

    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:

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Dynamic lists of subpages?’ is closed to new replies.