1

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

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

<?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(); ?>
4

2 回答 2

7

我想到了。希望其他有这个问题的人能找到这个!我找到了get_pages的wordpress codex:http: //codex.wordpress.org/Function_Reference/get_pages

<?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 } ?>
于 2013-07-07T04:36:05.350 回答
0
<?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; ?>
于 2016-06-19T18:01:27.610 回答