Your problem is that you’re using query_posts()
, when you need to be using WP_Query()
. To display all posts (by ignoring pagination, use the posts_per_page
parameter:
$cat_query_args = array(
// Include posts from category with ID $cat_id
'cat' => $cat_id,
// Include all posts
'posts_per_page' => -1
);
$cat_query = new WP_Query( $cat_query_args );
if ( $cat_query->have_posts() ) :
?>
<div id="sidebar">
<h3><?php echo get_cat_name($cat_id); $theCount = 0; ?></h3>
<ul class="info-list">
<?php
while ( $cat_query->have_posts() ) : $cat_query->the_post();
$theCount += 1; echo 'debug>' . $theCount;
?>
<li <?php if ($post_id == get_the_ID()) {echo 'class="active"';} ?>>
<a href="https://wordpress.stackexchange.com/questions/74082/<?php the_permalink(); ?>">
<span><?php the_title(); ?></span>
</a>
</li>
<?php
endwhile;
?>
</ul>
</div>
<?php
endif;
// Be kind; rewind
wp_reset_postdata();