Tec*_*ude 1 wordpress parent-child
我有自定义的帖子类型设置 - 称为项目和启用的子页面.当我在父页面上时,我想查询父页面上子页面的内容.
这是我的尝试.这将查询称为项目的所有自定义帖子类型 任何人都可以帮我查询子页面吗?
<?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(); ?>
Run Code Online (Sandbox Code Playgroud)
我想到了.希望有其他人有这个问题会发现这个!我找到了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 } ?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8050 次 |
| 最近记录: |