2016-05-23 66 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

該死的,我是失明的。非常感謝!! –

相關問題