• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Listing all children of a particular page, but not grand children or siblings

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Listing all children of a particular page, but not grand children or siblings

This topic is: not resolved

Tagged: Child Pages, sub pages, wp_list_pages

  • This topic has 3 replies, 2 voices, and was last updated 8 years, 8 months ago by Brad Dalton.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • March 11, 2018 at 2:47 pm #217763
    stinaq
    Member

    I'm trying my best to list all subpages to the current page, but not siblings or grand children, but I can't get it to work. I want the link to the page, as well as the featured image.
    With the following code I can get it to list siblings, children and grand children, which is not what I want :/

    function list_my_child_pages( $post ) {
        // if(!$post->post_parent) $my_page_id = $post->ID;
        // elseif($post->ancestors) $my_page_id = end($post->ancestors);
    
        $list_p = array(
            'sort_column' => 'menu_order, post_title',
            'child_of' => $post->ID,
            'sort_order' => 'ASC'
        );
    
        $children = get_pages($list_p); 
    
        $result = "<ul>";
        foreach ( $children as $child )
        {
            $child_id = $child->ID;
            $url  = get_permalink( $child_id );
            $thumb = get_the_post_thumbnail($child_id, array(240, 240));
            $title= $child->post_title;
        
            $link = "<a href='$url'><div class='child_page_thumb'>$thumb</div><div class='child_page_title'>$title</div></a>";
        
            $result .= "<li>$link</li>";
        }
     
        $result .= "</ul>";
    
        echo $result;
    }
    March 11, 2018 at 10:06 pm #217800
    Brad Dalton
    Participant

    Try wp_list_pages with the child_of arg https://developer.wordpress.org/reference/functions/wp_list_pages/


    Tutorials for StudioPress Themes.

    March 11, 2018 at 10:35 pm #217804
    Brad Dalton
    Participant

    get_pages : Note that the child_of parameter will also fetch "grandchildren" of the given ID, not just direct descendants.

    Use wp_list_pages and set to the depth parameter to '1'

    'depth' => 1, 
    

    Tutorials for StudioPress Themes.

    March 11, 2018 at 11:05 pm #217805
    Brad Dalton
    Participant

    Like this https://gist.github.com/braddalton/45d27d46ae79e3500184d3fbfd996700


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble