Reputation: 183
I am trying to configure my category.php in wordpress to show the posts which belong to a specific category.
This is the code of my category.php I'm currently using:
<?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>
<?php } } else { ?>
<p><?php _e( 'Die Posts entsprechen nicht den Kriterien.' ); ?></p>
<?php } ?>
<!-- end of the loop -->
<?php wp_reset_postdata(); ?>
</main>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
The code looks good but the problem is that all of the posts which are in index.php are displayed.
I hope that someone could help me! Thanks in advance!
Upvotes: 0
Views: 64
Reputation: 9951
Remove the custom query, that is your issue. Your loop should look something like this:
while ( have_posts() ) :
the_post();
// The rest of your loop code
endwhile;
Upvotes: 2