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

该死的,我是失明的。非常感谢!! –

相关问题