If you have 8 categories, you need 8 queries. To improve your code use WP_Query
instead of query_posts
:
<?php
$categories = get_categories();
if ( ! empty($categories) ) {
?>
<ul class="tabs">
<?php foreach ($categories as $c ) { ?>
<li>
<a href="#tab<?php echo $c->term_id; ?>">
<img src="<?php bloginfo('template_directory'); ?>/images/logo-<?php echo $c->slug; ?>.png" alt="<?php echo $c->name; ?>" />
</a>
</li>
<?php } ?>
</ul> <!-- / .tabs -->
<?php } ?>
<?php if ( ! empty($categories) ) { foreach ($categories as $c ) { ?>
<div id="tab<?php echo $c->term_id; ?>">
<a href="#" class="left-button"><img src="prev.png" alt="Prev" /></a>
<div class="content">
<?php
$q = new WP_Query( array( 'posts_per_page' => -1, 'cat' => $c->term_id ) );
if ( $q->have_posts() ) : ?> <ul> <?php while( $q->have_posts() ) : $q->the_post();
?>
<li>
<h3>
<a href="https://wordpress.stackexchange.com/questions/108557/<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a>
</h3>
<p><?php the_content(); ?></p>
</li>
<?php endwhile; ?> </ul> <?php endif; wp_reset_postdata(); ?>
</div><!-- / .content -->
<a href="#" class="right-button"><img src="next.png" alt="Next" /></a>
</div><!-- / #tab<?php echo $c->term_id; ?> -->
<?php } } ?>