0
주어진 $ args를 기반으로 게시물을 출력하는 정상적인 루프가 있습니다. 3 개의 게시물 뒤에 추천 카테고리의 게시물을 삽입하고 싶습니다. 나는 새로운 조합을 사용하여 새로운 WP_Query, 간단한 query_posts를 시작하려고 시도했다. 아무것도 작동하는 것 같습니다. 어떤 아이디어?루프 내부의 Wordpress 루프
$args = array(
'post_type' => 'post',
'posts_per_page' => $count,
'paged' => $paged,
'page' => $paged,
'cat' => $cat,
'ignore_sticky_posts' => 1
);
// create a new instance of WP_Query
$my_query = new WP_Query($args);
<ul>
<?php
$i = 0;
if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();
if($i == 3): ?>
<li> //insert here one post from featured category
</li>
<?php endif; ?>
<li>
// the normal query stuff is here
</li>
<?php $i++ //post counter
endwhile; //end loop while
endif; //end loop
?>
</ul>
http://wordpress.stackexchange.com/questions/130009/how-to-merge-two-queries-together – rnevius
그래서 get_post를 사용하여 기대, 루프 내부의 게시물을 얻을 수있는 다른 방법() 작동하지만 정확한 ID가 필요합니까? – CiprianD
the_post()를 할 때'$ post' 변수에서 무엇이든 접근하고 설정할 수 있어야합니다. 그래서 먼저 기능 쿼리를 실행하고'$ featured = $ post'와 같이 자신의 변수에 해당 아이템의 내용을 설정하십시오 -'$ i == 3' 조건문에서'$ feature-> post_title'라고 말할 수 있습니다. 'get_permalink ($ feature-> ID)'등등. 다른 루프 안에서 루프를 돌릴 필요는 없다. –