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 having trouble while i added query to loop.

please have a look whats the problem.

here is the link

 <div class="fl" id="main_article">
 <?php $count = 1;
 $the_query = new WP_Query( 'category_name=headline&orderby=post_date&order=desc' );

    if ( $the_query->have_posts() ) : while (have_posts()) : $the_query->the_post();       if($count == 1) : ?>

 <a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_title(); ?></a>
 <?php dynamic_excerpt(400); ?>
 <?php else : ?>

 <div class="post">
 <a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_title(); ?></a>
 <?php dynamic_excerpt(400); ?>  </div>

 <?php if ($count== 2 || $count == 4 ){ ?>  

 <?php dynamic_sidebar('index-insert') ?>
 <?php } ?>
 <?php $count = $count + 0; ?>
    <?php endif; ?>
<?php $count++; ?> 
<?php endwhile; ?> </div>
share|improve this question
up vote 1 down vote accepted

no idea what the problems actually are, but from looking at the code, I woud suggest:

a: the while (have_posts()) : should be while ($the_query->have_posts()) :

b: you would need to increment the counter: <?php $count = $count + 1; ?>

c: the endif; of the loop might be missing after the endwhile; - at least it is not shown in the posted code section.

share|improve this answer
thanks for your reply !! done here is the <?php $count = 1; $the_query = new WP_Query('category_name=headline&orderby=post_date&order=desc'); if ($the_query->have_posts()) :?> <?php while ($the_query->have_posts()) : $the_query->the_post(); if($count == 1) : ?> – Nisha_at_Behance Jul 19 '12 at 10:51
what is or was the actual problem with the code? – Michael Jul 19 '12 at 12:06

Your Answer


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.