2012-01-06 5 views
0

私はページID#20の子ページを取得するためにwordpressでカスタムクエリを作成しています。page.phpのクエリのみページの子供

そして唯一のID を持つページに表示されるように#20#95#97

<?php if (is_page(array('20','95','97'))) /* RIDERS */ { query_posts(array(

    'post_type' => 'page', 

    'child_of' => 20, 

    'order' => 'DESC' 

)); } ?> 

<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 

    <!-- my loop stuff here -->   

<?php endwhile; endif; wp_reset_query(); ?> 

私の最初の問題は、このループは私のpage.phpテンプレートファイルであるということです(メインページループ外)。そして何らかの理由で上記のクエリでページデータが表示されています。上記のクエリをどのようにして、ページ上の他のループに干渉しないようにするにはどうすればよいですか。私は私のpage.phpテンプレートに2 <?php if (have_posts()) : while (have_posts()) : the_post(); ?>があるからだと思う。

私の次の質問は、この質問を正しく書いたかどうかです。ページID#20の子ページ以外のページをリストしているようです。

ありがとうございました。

ジョシュ

答えて

0

どのように役立ちます

<?php 
// just show this on your selected pages.. 
if (is_page(array('20','95','97'))) /* RIDERS */ { 
    query_posts(array('post_type' => 
        'page','child_of' => 20, 
        'order' => 'DESC' 
        ) 
      ); 
    if (have_posts()) : while (have_posts()) : the_post(); 
?> 
    <!-- my loop stuff here --> 
<?php 
    endwhile; 
    else: 
?> 
    <h2>No Content</h2> 
<?php 
    endif; 
}else{ 
//else just show normal post 
    if (have_posts()) : while (have_posts()) : the_post(); ?> 
     <!-- my loop stuff here --> 
<?php 
    endwhile; 
    else: 
?> 
    <h2>No Content</h2> 
<?php 
    endif; 
} //end of normal post 
?> 

希望のようなものでしょうか? M ..

ちょうどポストバックを読んで、あなたのループに表示したいものによっては、wp_list_pages()を使ってサブページを表示する方が良いでしょうか?親のページ。

+0

ありがとうmarty - これはうまくいきました。 – Joshc

関連する問題