WordPress.org

Forums

[resolved] wp_list_pages Question (4 posts)

  1. creative_lounge
    Member
    Posted 2 years ago #

    Hi,

    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,

  2. martha_camellia
    Contributor Day Volunteer
    Posted 2 years ago #

    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.

  3. creative_lounge
    Member
    Posted 2 years ago #

    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,

    Cheers

  4. creative_lounge
    Member
    Posted 2 years ago #

    Wow figured it out..so 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.
    http://www.webcitizenmag.com/2010/05/20/how-to-get-top-parent-page-id-in-wordpress/

    Hope this helps others,
    Thanks again

Topic Closed

This topic has been closed to new replies.

About this Topic