Title: Troubles using wp_list_pages
Last modified: August 19, 2016

---

# Troubles using wp_list_pages

 *  [whooper](https://wordpress.org/support/users/whooper/)
 * (@whooper)
 * [17 years, 8 months ago](https://wordpress.org/support/topic/troubles-using-wp_list_pages/)
 * 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)

 *  [10sexyapples](https://wordpress.org/support/users/10sexyapples/)
 * (@10sexyapples)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/troubles-using-wp_list_pages/#post-920442)
 * 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
 *  [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/troubles-using-wp_list_pages/#post-920443)
 * 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.

## Tags

 * [pages](https://wordpress.org/support/topic-tag/pages/)
 * [wp_list_pages](https://wordpress.org/support/topic-tag/wp_list_pages/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * Last activity: [17 years, 6 months ago](https://wordpress.org/support/topic/troubles-using-wp_list_pages/#post-920443)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
