In Header file I have added

while ( have_posts() ) : the_post();  ?>
<img src='banner.jpg' />
<?php }  ?>

` But in Search page the banner is loop equal to number of results. How can i avoid this. I want to show banner just one time in search page


You have the header inside the Loop, so of course it prints once for each result. Put that outside the Loop proper.

if (have_posts()) { ?>
  <img src='banner.jpg' /><?php
  while ( have_posts() ) {
    // print contents

Also, don't use relative URLs in WordPress. You are in for all kinds of headache if you try.

  • Is have->posts() a thing or do you mean have_posts() ? :) – a web dev Jun 12 '13 at 20:11
  • Fixed it. Just a typo. – s_ha_dum Jun 12 '13 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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