특정 카테고리 내의 모든 게시물을 나열하는 맞춤 게시물 쿼리가 있습니다. 예를 들어 다음과 같습니다.

$args = array("cat" => "home","post_type" => "post")); $post_obj = new WP_Query($args); while($post_obj->have_posts() ) : $post_obj->the_post(); // do stuff here endwhile; 

이 페이지에서는 게시물 목록과 함께 제공되는 댓글도 표시하고 싶습니다. 각 게시물에 대해 최대 2 개의 댓글 만 표시하고 있습니다.

이 작업을 수행하는 내장 함수가 있습니까?

답변

. 기능 참조 / 댓글 가져 오기

$args = array("cat" => "home","post_type" => "post")); $post_obj = new WP_Query($args); while($post_obj->have_posts() ) : $post_obj->the_post(); //display comments $comments = get_comments(array( "post_id" => $post->ID, "number" => "2" )); foreach($comments as $comment) { //format comments } endwhile; 

답글 남기기

이메일 주소를 발행하지 않을 것입니다. 필수 항목은 *(으)로 표시합니다