2012-04-23 2 views
0

홈페이지에서 여러 개의 루프를 사용하고 싶습니다. 먼저 특정 카테고리의 게시물을 표시 한 다음 위에 포함 된 카테고리를 포함한 모든 게시물을 표시하려고합니다. 그러나 query_posts를 사용하지 않고 두 번째 루프를 사용하면 이전 루프의 게시물이 제외됩니다. 예를 들어WordPress : 여러 게시물 루프를 사용하고 계십니까?

:

<div class="special_category" > 
    <?php query_posts('category_name=special_cat&posts_per_page=10'); ?> 
     <?php while (have_posts()) : the_post(); ?> 
      <!-- will get special_cat posts --> 
     <?php endwhile;?> 
</div> 

<div class="latest_posts"> 
     <!-- as i want do display all posts, so I don't use query_posts. --> 
     <?php while (have_posts()) : the_post(); ?> 
      <!-- this will exclude the posts of above special_cat --> 
     <?php endwhile;?> 
</div> 

I는 QUERY_STRING을 사용하는 경우

번째 루프 (심지어 인수를 통하지 않고)은 다음의 포스트를 포함한다.

<div class="latest_posts"> 
     <!-- i used query_posts without any arguments --> 
     <?php query_posts(''); ?> 
     <?php while (have_posts()) : the_post(); ?> 
      <!-- now this will get all posts --> 
     <?php endwhile;?> 
</div> 

내 질문은 바로 그런 의미입니다. 위의 루프의 게시물을 제외하거나 내가 잘못하고있는 것입니까? 왜 그것은 query_posts를 사용하지 않고 모든 게시물을 얻지 못할까요? 감사합니다. . 당신은 여러 게시물이 wp_query를 사용해야 루프를 사용하는 경우가

첫 번째 루프 후 여기 http://codex.wordpress.org/Function_Reference/wp_reset_query

답변

1

첫 번째 쿼리는 두 번째 루프에 영향을 미칠 것입니다.
그런 식으로 쿼리를 다시 설정할 필요가 없습니다.

+0

감사합니다. 그것은 굉장했다 :) – user966582

0

더 많은 정보를 <?php wp_reset_query(); ?> 추가 초기화 할 때까지

관련 문제