2016-05-23 13 views
0

私は特定のカテゴリに属する​​投稿を表示するためにwordpressで私のcategory.phpを設定しようとしています。WPのcategory.phpがすべての投稿を表示しているのはなぜですか?

私は現在使用しています。これは、私のcategory.phpのコードです:

<?php get_header(); ?> 
 
    
 
    <div id="site-wrapper"> 
 
     
 
     <main id="main"> 
 
      
 
      
 
      <h2 id="category_title"><a href="#">Kategorie "<?php single_cat_title('', true); ?>"</a></h2> 
 
      
 
       <?php 
 
       // the query 
 
       $args = array('posts_per_page' => -1); 
 
       $the_query = new WP_Query($args); 
 
      
 
       ?> 
 
      
 
       <?php if ($the_query->have_posts()) { ?> 
 
      
 
        <!-- loop --> 
 
      
 
        <?php while ($the_query->have_posts()) { 
 
         
 
           $the_query->the_post(); ?> 
 
      <article id="post_cat"> 
 
        
 
         <div id="thumbnail"> 
 
         
 
          <?php if (has_post_thumbnail()) : ?> 
 
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> 
 
    <?php the_post_thumbnail(); ?> 
 
</a> 
 
<?php endif; ?> 
 
        
 
        </div> 
 
        
 
        <h2><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h2> 
 
        
 
        <div class="entry"> 
 
        
 
         <?php the_excerpt(); ?> 
 
         
 
        </div> 
 
        
 
      
 
      </article> 
 
      
 
\t 
 
    
 
       <?php } } else { ?> 
 
       <p><?php _e('Die Posts entsprechen nicht den Kriterien.'); ?></p> 
 
       <?php } ?> 
 
    \t \t \t 
 
       <!-- end of the loop --> 
 
\t 
 
    
 
       <?php wp_reset_postdata(); ?> 
 
     </main> 
 
    
 
    
 
<?php get_sidebar(); ?> 
 
<?php get_footer(); ?>

をコードがよさそうだが、問題は、インデックス内にあるポストのすべてのことです。 phpが表示されます。

誰かが私を助けてくれることを願っています!前もって感謝します!

答えて

2

カスタムクエリを削除することが問題です。あなたのループは次のようになります。

while (have_posts()) : 
    the_post(); 

     // The rest of your loop code 

endwhile; 
+0

くそー、私は目が見えませんでした。どうもありがとうございます!! –

関連する問題