WordPress-在子页面上显示子页面(标题和缩略图)

WordPress-在子页面上显示子页面(标题和缩略图),wordpress,Wordpress,我使用下面的代码在侧边栏中显示子页面列表和这些子页面中的特色文章图像(当在父页面上时) <?php $args = array( 'orderby' => 'menu_order', 'order' => 'ASC', 'post_parent' => $post->ID, 'post_type' => 'page', 'post_status' => 'publish'

我使用下面的代码在侧边栏中显示子页面列表和这些子页面中的特色文章图像(当在父页面上时)

<?php $args = array(
        'orderby' => 'menu_order',
        'order' => 'ASC',
        'post_parent' => $post->ID,
        'post_type' => 'page',
        'post_status' => 'publish'
        ); 
        $postslist = get_posts($args);
        foreach ($postslist as $post) : setup_postdata($post); 
    ?>
    <div class="top10">
    <a href="<?php the_permalink();?>">
    <?php the_post_thumbnail('large'); ?>
    </a>
    </div>
    <?php endforeach; ?>
    <?php wp_reset_query(); ?>

但是,当在其中一个子页面上时,我还需要在侧边栏中显示相同的列表。当前,使用相同的代码而不进行调整时,在子页面上不会显示任何内容

我尝试将“'post\u parent'=>$post->ID”行更改为“'post\u parent'=>$post->ID.“echo=0”,这显示了一些子页面,但不是所有子页面,所以我显然弄糟了一些东西

有人能帮我修改代码,使其在父级的子页面上工作,以及在父级上工作吗

谢谢
Zach使用此功能为菜单生成ID。它将确定页面是否有父级,并使用该ID,否则返回当前页面ID

function get_menu_id(){
    if ($post->post_parent)  {
        $parent = get_post_ancestors($post->ID);
        return $parent[0];
    } else {
        return $post->ID;
    }
}
完整代码

<?php 


function get_menu_id(){ //this function would be better off in your functions.php file
        if ($post->post_parent)  {
            $parent = get_post_ancestors($post->ID);
            return $parent[0];
        } else {
            return $post->ID;
        }
    }
$args = array(
        'orderby' => 'menu_order',
        'order' => 'ASC',
        'post_parent' => get_menu_id(),
        'post_type' => 'page',
        'post_status' => 'publish'
        ); 
        $postslist = get_posts($args);
        foreach ($postslist as $post) : setup_postdata($post); 
    ?>
    <div class="top10">
    <a href="<?php the_permalink();?>">
    <?php the_post_thumbnail('large'); ?>
    </a>
    </div>
    <?php endforeach; ?>
    <?php wp_reset_query(); ?>


您不能使用wordpress菜单吗?wordpress菜单通常只显示页面标题,而演示的方法允许我根据需要拖动缩略图、标题,甚至摘录!那么您遇到的问题是自动获取父页面ID?我说得对吗?我相信是的。看一看-这是父页面,您可以看到它在左侧列出了所有子页面,按照上面的代码。现在单击其中一个子页面,您可以看到左侧没有显示任何内容,代码相同。我需要修改代码以显示子页面左侧的项目以及父项我想我理解您的问题。。。