WordPress.org

Ready to get started?Download WordPress

Forums

Display Children only. (4 posts)

  1. Adam Huxtable
    Member
    Posted 1 year 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 1 year ago #

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

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

  3. Adam Huxtable
    Member
    Posted 1 year ago #

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

  4. alchymyth
    Forum Moderator
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic