I am trying to display a bunch of posts from a single category on the category page, using multiple loops.

<div id="featured-content" class="clearfix">

// assign the variable as current category
$categoryvariable = $cat;

<?php query_posts('$cat'); ?>
<?php $posts = get_posts('numberposts=1&offset=0&category=$cat'); foreach ($posts as $post) : start_wp(); ?>
<?php static $count1 = 0; if ($count1 == "1") { break; } else { ?>

        <article class="d-all d-pad">
            <ul class="meta">
                <li class="date"><?php echo get_the_date('d.m.Y'); ?></li>
                <li class="region"><?php the_terms( $post->ID, 'regions' ,  ' ' ); ?></li>
                <li class="cat"><?php the_category(', ') ?></li>
            <?php if(has_post_thumbnail()) :?>
                <figure class="img clearfix">
                <?php the_post_thumbnail( 'featured-image', array( 'class' => 'featured-image' ) ); ?>
            <?php else :?>
            <?php endif;?>
            <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
            <?php the_excerpt();?>

<?php $count1++; } ?>
<?php endforeach; ?>

What am I doing wrong as its not displaying the articles for the category page I am on.


1 Answer 1


You're doing query_posts and then immediately get_posts. This looks wrong. Remove the query_posts call.

Also, where does your $cat come from? It doesn't appear to be set anywhere in your code snippet. Try to start with setting it first:

$cat = get_query_var('cat');
  • Basing it on this page, digwp.com/2010/03/wordpress-post-content-multiple-columns point 4. I have multiple loops on the page. Also the $cat is being set. <? // assign the variable as current category $categoryvariable = $cat; echo($cat); ?> That display a number, which is the category id, so I know it works.
    – Nick Toye
    Commented Apr 26, 2013 at 14:41
  • Read this for a discussion on why using query_posts is a bad idea. Author of tutorial himself agrees. As for $cat, in PHP assignment operator works from right to left. The variable is most likely being set somewhere higher up, that's why it's defined. Whole line $categoryvariable = $cat; is therefore useless. Commented Apr 26, 2013 at 14:57
  • Sorry, I just don't understand.
    – Nick Toye
    Commented Apr 29, 2013 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.