Problem with loop in single.php
-
I’m making a loop (using multiple loops) in order to show the related post from the main article category. The problem is that the loop prints the last posts from the month when I specified a category ID.
Note: I obtain the category ID before and it’s contained on the $categoria variable. If i “echo” the $categoria inside the loop, it shows me the correct ID, but i don’t know why is not working.
The same code works well on index.php but not here:
`<?php $events_query = new WP_Query(“‘cat=”.$categoria.”&posts_per_page=3′”); ?>
<?php $postnum = 0;?>
<?php if(have_posts()) : ?><?php while($events_query->have_posts()) : $postnum = $postnum + 1; $events_query->the_post(); ?>
<?php if ($postnum > 1 ) { ?>
<div class=”cuadrorelated”>
<div class=”imagenrelated”>
<?php if(has_post_thumbnail()) { ?>
<?php the_post_thumbnail(‘posthumb’); ?>
<?php } else {?>
<img src=”<?php bloginfo(‘template_directory’); ?>/images/hemeroteca.jpg” />
<?php } ?>
<h1 class=”negrocentro”>“><?php the_title(); ?></h1>
</div>
</div>
<?php } ?>
<?php endwhile; ?>
<?php endif; ?>Thanks
- The topic ‘Problem with loop in single.php’ is closed to new replies.