• Hey guys,

    I’ve got some issues using the wp_list_pages template tag twice on one HTML page, once in the page.php and once in the sidebar.php (doesn’t matter if hardcoded or as widget).

    First thing I would like to do is a “table of content” with all subpages of the current page:

    $sub_pages = wp_list_pages('title_li=&child_of='.$post->ID.'&sort_colum=post_name&echo=0');
    if($sub_pages) {
        echo '<div style="border: 1px solid red; margin: 10px auto; width: 90%;">';
        echo '<div style="margin: 10px; font-weight: bold;">Inhaltsverzeichnis <span style="font-weight: normal;">[<a href="#" onclick="switchDirectory();" id="switcher">Anzeigen</a>]</span></div>';
        echo '<ol id="directory" class="directory-hide">';
        echo $sub_pages;
        echo '</ol>';
        echo '</div>';
    }

    Second thing is a list will alle subpages of the post->parent page in the Sidebar:

    <li>
                    <ul>
    <?php $related_pages = wp_list_pages('title_li=&depth=1&child_of='.$post->post_parent.'&sort_colum=post_name&echo=1'); ?>
                    </ul>
                </li>

    If I execute both scripts for its own, they work perfect. But if I have both on one page, the HTML output stops directly before the second call.

    Unfortunately there are no PHP errors and the $post variable is correct.

    Anyone an idea what the problem can be?

    THX in advance!

    Cheers
    Whooper

Viewing 2 replies - 1 through 2 (of 2 total)
  • I am experiencing this same issue, and have found several unanswered topics on this scattered all the way back to 2005. Can anyone shed some light on how to deal with this and facilitate using the wp_list_pages function twice? My main header navigation is a list of pages, and now, I need to have a page whose template carries a completely different list of pages within it, and for the life of me can’t find any solutions to make this possible. I read a post from a while back about someone uncaching the list pages function so that they could use it twice, but, does it really take doing this? Any help would be greatly appreciated.
    Thank you,
    Angie

    Whooper… I’m not sure if you forgot to put something, but in your second example you’ve assigned wp_list_pages to the $related_pages variable…

    but you haven’t echoed the variable. Try this:

    <li>
                    <ul>
    <?php wp_list_pages('title_li=&depth=1&child_of='.$post->post_parent.'&sort_colum=post_name&echo=1'); ?>
                    </ul>
                </li>

    or just echo the variable after you define it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Troubles using wp_list_pages’ is closed to new replies.