Dynamic category name in query post

You shouldn’t use query_posts functions. You should create instance of WP_Query class

In your theme folder create a new file called category-slug.php. You can copy the category.php file or archive.php file to create category-slug.php file.

Then in the new category-slug.php file before the while loop you can write your query.

$query = new WP_Query( 'category_name=apple,pears' );

<?php if ( $the_query->have_posts() ) : ?>

    <!-- pagination here -->

    <!-- the loop -->
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <h2><?php the_title(); ?></h2>
    <?php endwhile; ?>
    <!-- end of the loop -->

    <!-- pagination here -->

    <?php wp_reset_postdata(); ?>

<?php else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

You might need to replace your existing while statement with this one.