Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress:在父页面上查询子页面内容_Wordpress_Parent Child - Fatal编程技术网

Wordpress:在父页面上查询子页面内容

Wordpress:在父页面上查询子页面内容,wordpress,parent-child,Wordpress,Parent Child,我有自定义的文章类型设置,称为项目,并启用了子页面。当我在父页面上时,我想查询父页面上子页面的内容 这是我的尝试。这将查询所有称为项目的自定义帖子类型。有人能帮我查询子页面吗 <?php $args = array( 'child_of' => $post->ID, 'post_type' => 'projects', 'order' => 'ASC', 'orderby' => 'me

我有自定义的文章类型设置,称为项目,并启用了子页面。当我在父页面上时,我想查询父页面上子页面的内容

这是我的尝试。这将查询所有称为项目的自定义帖子类型。有人能帮我查询子页面吗

<?php

$args = array(

    'child_of' => $post->ID, 
    'post_type' => 'projects', 

    'order'          => 'ASC',
    'orderby'        => 'menu_order'
 );


$wpq = new WP_Query( $args );
if( $wpq->have_posts() ): while( $wpq->have_posts() ): $wpq->the_post(); ?>

        <div id="parent-<?php the_ID(); ?>" class="parent-page">
            <?php echo the_content();?>
        </div>

    <?php endwhile; ?>

<?php endif; wp_reset_query(); ?>


我想出来了。希望其他有这个问题的人都能找到这个!我找到了get_页面的wordpress代码:


我想出来了。希望其他有这个问题的人都能找到这个!我找到了get_页面的wordpress代码:





通过将$post->ID更改为所需父页面的数字ID,您也可以更改此选项以从特定页面的子页面绘制内容。Ex'parent'=>10您也可以通过将$post->ID更改为所需父页面的数字ID来更改此选项,以从特定页面的子页面绘制内容。前“父项”=>10
<?php $children = get_pages( 
    array(
        'sort_column' => 'menu_order',
        'sort_order' => 'ASC',
        'hierarchical' => 0,
        'parent' => $post->ID,
        'post_type' => 'projects',
    ));

foreach( $children as $post ) { 
        setup_postdata( $post ); ?>
    <div class="section-container">
        <?php the_content(); ?>
    </div>
<?php } ?>
<?php

$query = array('post_parent' => $post->ID, 'post_type' => 'page', 'posts_per_page' => '3','orderby' => 'date','order' => 'DESC');


                $loop = new WP_Query($query);

            if ($loop->have_posts()) : while ($loop->have_posts()) : $loop->the_post();
            ?>
                    <div class="section-container">
                        <?php echo wp_trim_words( get_the_content(), 40, '...' ); ?>
                    </div>


            <?php endwhile; endif; ?>