2013-01-14 16 views
0

在WordPress在search.php中我有這不會工作..WordPress的側邊欄循環時的search.php時沒有找到的結果

get_header(); ?> 
...html/css 
<?php if (have_posts()) : ?> 
<?php while (have_posts()) : the_post(); 
...loop stuff 
<?php endwhile; ?> 
<?php wp_pagenavi(); ?> 
<?php else : ?> 
<h3><?php _e('Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'hartyinternational'); ?></h3> 
        <div class="nothing-found"><?php get_search_form(); ?></div> 
    <?php endif; ?> 
    <?php wp_reset_query(); ?> 

然後我建立我自己的側邊欄與WP_Query循環, 例如

if (have_posts()) : 
$counter = 0; 

      $the_query = new WP_Query(array('posts_per_page' => 5, 'cat' => 4)); 
      while ($the_query->have_posts()) : $the_query->the_post(); 
      $counter++; 
      if ($counter == 1 || $counter == 3 || $counter == 5 ){ 
      ?> 
      <a href="<?php the_permalink(); ?>"><div class="recent-position-single"><?php the_title(); ?></div> </a> 
     <?php } 
      else { 
      ?> <a href="<?php the_permalink(); ?>"><div class="recent-position-single darker-shade"><?php the_title(); ?></div> </a> 
     <?php } 



      endwhile; 
wp_reset_query(); 
endif; 
wp_reset_postdata(); ?> 

和另一個相似的一個, 這些工作時,搜索結果中發現完全沒問題,但如果沒有結果發現環路無法加載任何內容,有什麼建議?

它看起來不像是一個循環內的循環或類似的情況,我似乎無法弄清楚什麼可能是錯誤的,任何幫助將是非常感謝。

+0

側邊欄加載,只是不加載任何查詢?或者它甚至沒有加載?您是否在邊欄中添加了一些額外的內容,以確保它在您的空搜索結果頁面上加載? –

+0

您好,我刪除了'if(have_posts()):'這似乎已經解決了這個問題,但感謝您的迴應。 – Adrian

+0

我很高興你能工作。 –

回答

0

我從我的查詢中移除if (have_posts()):並解決了問題。