Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to limit my loop to one category. This is the loop:

<?php
$counter = 1; //start counter

$grids = 3; //Grids per row

global $query_string; //Need this to make pagination work


/*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts) */
query_posts($query_string . '&caller_get_posts=1&posts_per_page=9&category=5');



if(have_posts()) :  while(have_posts()) :  the_post(); 
?>
<?php
//Show the left hand side column
if($counter == 1) :
?>
            <div class="four columns">
                <div class="postimage">
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('home-thumb'); ?></a>
                </div>
                <h3 style="text-align:center;"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                <p><?php the_excerpt(); ?></p>
            </div>
<?php
//Show the middle column
elseif($counter == $grids) :
?>
<div class="four columns">
                <div class="postimage">
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('home-thumb'); ?></a>
                </div>
                <h3 style="text-align:center;"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                <p><?php the_excerpt(); ?></p>
            </div>
<?php
//Show the right hand side column
elseif($counter == $grids) :
?>
<div class="four columns">
                <div class="postimage">
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('home-thumb'); ?></a>
                </div>
                <h3 style="text-align:center;"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                <p><?php the_excerpt(); ?></p>
            </div>          

<div class="clear"></div>
<?php
endif;
?>

<?php
endwhile;
//Pagination can go here if you want it.
endif;
?>

This is the page temp.

<?php
/*
Template Name: Web Design
*/
 get_header(); ?>
<hr>

    <div  id="content" class="twelve columns">

        <?php get_template_part('loop', 'web'); ?>

    </div>

<?php get_footer(); ?>

It is not working. Please help. Thanks.

share|improve this question
add comment

1 Answer

There is no category argument for query_posts, a category ID should be passed via cat.

However, if this is an additional query, please use WP_Query rather than query_posts. If this is the main query, please see pre_get_posts to alter the main query parameters.

For more info please see When to use WP_query(), query_posts() and pre_get_posts.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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