php - Get Child of Child Pages in custom Menu

Got this bit of code which runs which gets the Page ID and displays all the children under it. Which is good. Part two o

Got this bit of code which runs which gets the Page ID and displays all the children under it. Which is good.

Part two of this is getting it to pull in the child of children items.

So currently looks like this

Main Menu Item
     Child Item
     Child Item
     Child Item

But I need it to look like this

Main Menu Item
     Child Item
          Child Item
          Child Item
          Child Item

This is the code I am using

<?php
    $args = array(
        'post_type'      => 'page',
        'posts_per_page' => -1,
        'post_parent'    => 92,
    );
    $parent = new WP_Query( $args );
    if ( $parent->have_posts() ) : ?>
        <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>
            <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
        <?php endwhile; ?>

    <?php endif; wp_reset_postdata(); ?>

Got this bit of code which runs which gets the Page ID and displays all the children under it. Which is good.

Part two of this is getting it to pull in the child of children items.

So currently looks like this

Main Menu Item
     Child Item
     Child Item
     Child Item

But I need it to look like this

Main Menu Item
     Child Item
          Child Item
          Child Item
          Child Item

This is the code I am using

<?php
    $args = array(
        'post_type'      => 'page',
        'posts_per_page' => -1,
        'post_parent'    => 92,
    );
    $parent = new WP_Query( $args );
    if ( $parent->have_posts() ) : ?>
        <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>
            <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
        <?php endwhile; ?>

    <?php endif; wp_reset_postdata(); ?>
Share Improve this question asked Jul 17, 2019 at 14:23 JamesJames 34 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can do what you need to with the wp_list_pages() function:

<?php
wp_list_pages(
    [
        'child_of'    => 92,
        'title_li'    => false,
        'sort_column' => 'menu_order',
    ]
);
?>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745315581a4622203.html

相关推荐

  • php - Get Child of Child Pages in custom Menu

    Got this bit of code which runs which gets the Page ID and displays all the children under it. Which is good. Part two o

    17小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信