2013-07-06 61 views
0

我有自定義的帖子類型設置 - 稱爲項目和啓用子頁面。當我在父頁面上時,我想查詢父頁面上的子頁面的內容。WordPress的:查詢父頁面上的子頁面內容

這是我的嘗試。這會查詢所有名爲項目的自定義帖子類型任何人都可以幫助我查詢子頁面嗎?

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

回答

6

我想通了。希望其他人有這個問題會發現這個!我發現get_pages WordPress的抄本: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 } ?> 
+0

你可以改變這個改變後$> ID所需父頁面的數字ID畫從一個特定頁面的兒童的內容,以及。 Ex 'parent'=> 10 – ioTus

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; ?>