2017-01-19 10 views
0

カテゴリをPAGE(投稿ではなく)に追加する方法を考え出しました。そして、私はちょうどポストループ内のページを表示する方法があった場合、これは私のコードであると思いまして。ポストループの内側にカテゴリIDでページを表示する

<?php query_posts('cat=540'); ?> 
      <div class="blog_module"> 


              <?php if(has_post_thumbnail()) { 
               the_post_thumbnail(array(150,150)); 
              } else { 
               echo '<img class="alignleft" src="'.get_bloginfo("template_url").'/images/empty_150_150_thumb.gif" width="150" height="150" />'; 
              } 
              ?> 


              <div class="entry"> 
               <h3 class="blog_header"><a href="<?php echo get_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h3> 
               <?php the_excerpt(); ?> 
               <a class="button_link" href="<?php the_permalink(); ?>"><span>Read More</span></a> 

              </div> 


            </div> 

しかし、これは表示されます。 enter image description here

私が望むものではありません。カテゴリーID 540に割り当てられたページではなく、ポストのみを表示します。

プリーア誰かがカテゴリに割り当てられたページを表示するループを手助けすることができました。

ありがとうございます。

答えて

0

確かに簡単です。私は(未テスト)以下は動作するはず推測:

query_posts(array('cat'=>540,'post_type'=>page)); 

あなたはまた、query_postsよりも柔軟であるWP_Queryを使用することができます。

$q = new WP_Query(array('cat'=>540,'post_type'=>page)); 

while($q->have_posts()): $q->the_post(); 
// your post here 
endwhile; 

これは、より柔軟であるべき:

$args = array(
    'post_type' => 'page', 
    'tax_query' => array(
     array(
      'taxonomy' => 'category', 
      'field' => 'id', 
      'terms' => 540 
     ), 
    ), 
); 
$query = new WP_Query($args); 

投稿とページが必要な場合:

'post_type' => 'すべての'

あなたはこれらのリンクを見つけることができます必要なすべての情報:https://developer.wordpress.org/reference/functions/query_posts/ https://codex.wordpress.org/Class_Reference/WP_Query

関連する問題