Support » Fixing WordPress » wp_list_pages Question

  • Resolved creative_lounge



    I am sure I can’t be far off, but for whatever reason I am unable to display child pages of a parent page.

    This is the code I am using :

    <?php global $post; ?>
    <?php wp_list_pages('title_li=&child_of='. $post->ID .''); ?>

    I am using global $post as it is outside the loop. I am wanting to use best practice of using a dynamic page ID. BTW If I do pipe through the ID manually it does work, so it is clearly my code relating to the page ID.
    I have tried and searched and now require some help to point me in the right direction.

    Thank you in advance,

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Paul:

    I just tried your code and it worked for me. (You don’t need the . ‘ ‘ after $post->ID though).

    When you say it doesn’t work, what happens? It sounds like $post is not set up when your code is called.

    Thanks Martha,

    Basically I get nothing printed. When you say $post is not set up, am missing some code then ? I am placing this code outside the loop but by declaring $post as a global variable I thought I could still access the whole post object.

    Thanks for your time helping me understand this Martha, appreciate it,


    Wow figured it the issue I had which I perhaps didn’t make clear is that I was trying to display child pages not only on the parent page itself but also on the child pages.

    The above code would have worked fine on the parent page alone, but as soon as I am on any child page $post->ID no longer refers to the top parent but instead the page I am on and will not work as intended.

    In this instance I stumbled this guys function which worked a treat.

    Hope this helps others,
    Thanks again

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