Confused with The Loop
-
Hi there guys, quick question, I have a category.php page. How it should work its pretty easy, when you click a category you’ll land on this page with all the posts associated to that category, however, there’s something wrong because it is printing all the posts no matter what category you are clicking on, this is part of my code, or at least, the code relevant to this question:
First I’m printing the Category name – This is actually working –
<div class="breadcrumbs-categories"><h1>NOTICIAS DE <?php echo single_cat_title(); ?> EN ESPA?OL</h1></div>
The The Loop – Which is not working –
<?php global $post; $args = array( 'numberposts' => 3 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?> <!-- START CONTENTS 1 --> <div class="title-categories"><h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3></div> <div class="date-categories"><?php the_time('F jS, Y') ?> Escrito por <?php the_author() ?></div> <!-- Start Contents --> <div class="maincontents-categories"> <p><?php echo substr(get_the_excerpt(), 0,500); ?></p> <p>?</p> <a href="<?php the_permalink(); ?>" class="readmore">Leer más...</a> </div> <?php endforeach; ?>
What Am I missing?? When I call a category it prints the category name but prints the first 4 posts no matter the category, any idea?
Thanks!
Arturo
- The topic ‘Confused with The Loop’ is closed to new replies.