WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to use an if statement with is_category() in order to build a bigger piece of code later. I can't get the code to recognize the if statement though. Basically below I've posted the coding with the if statement commented out. It works without the if statement but if I uncomment the if statement (and the closing curly bracket) then there is an error and the page doesn't display. I am only checking this on a category page so I assumed it should recognize that it is a category page and display the posts (I can understand it being a problem if I was on a 'tag' archive page, etc.). Why would this have a problem displaying?

/*if (is_category()) {*/
if ($paged == 0)
  $offset = 0;
  $offset = ($paged - 1) * 11;
global $post;
$category = get_the_category($post->ID);
$category = $category[0]->cat_ID;
$myposts = get_posts(array('numberposts' => 11, 'offset' => $offset, 'category__in' => array($category), 'post__not_in' => array($post->ID),'post_status'=>'publish'));
foreach($myposts as $post) :
share|improve this question
where is that code in the context of the whole template? – Michael Jul 25 '12 at 23:24

Your Answer


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

Browse other questions tagged or ask your own question.