WordPress.org

Forums

Display Children only. (4 posts)

  1. Adam Huxtable
    Member
    Posted 2 years ago #

    I am using the following code to display the child of my parent pages, but it is also displaying the children of the child pages (not sure if there is an exact term for that, lol)

    <?php
                        $subnav_parent = ($post->post_parent) ? $post->post_parent : $post->ID;
                        $pages = get_pages('child_of=' . $subnav_parent . '&sort_column=menu_order');
                        $count = 0;
                        foreach($pages as $page)
                        { ?>
    
                        <ul>
                            <li>
                            <h5 class="del_subnav">
                                <a href="<?php echo get_page_link($page->ID)  ?>" ><?php echo  $page->post_title ?></a>
                            </h5>
                            </li>
                            </ul>
                        <?php
                        }
                        ?>
                        </div>

    So is there a way to just display the children of the parent?

    Thanks
    Adam

  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    try to use the 'parent' parameter instead of 'child_of'

    http://codex.wordpress.org/Function_Reference/get_pages

  3. Adam Huxtable
    Member
    Posted 2 years ago #

    That just brings up all of the parent pages within the site.

  4. alchymyth
    Forum Moderator
    Posted 2 years ago #

    what code did you use with the 'parent' parameter?

Topic Closed

This topic has been closed to new replies.

About this Topic