I think you’re asking about your custom secondary loop affecting your main loop, correct?
query_posts()
alters the main loop. A quick fix would be to call wp_reset_query()
after your custom loop to reset the query data:
<?php wp_reset_query(); ?>
However, it’s more efficient and friendlier to use WP_Query()
instead of query_posts()
(especially if you’re making a secondary loop). This should be the equivalent of your provided code using WP_Query()
:
<?php
if ( is_category() ) {
$current_cat = get_query_var('cat');
}
$args = array(
'category__and' => array( 55, $current_cat )
);
$my_query = new WP_Query( $args );
?>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<li>
<a href="https://wordpress.stackexchange.com/questions/83176/<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
References: