는 또한 각 서브 카테고리의 첫 포스트로부터 메타 데이터를 반환한다 3.워드 get_categories() 문제
함수의 번호와 상위의 서브 카테고리를 나열하도록 구성되어있는, 아래의 함수를 작성한 .
이 방법이 효과적이지만 데이터 세트를 하나만 가져 오는 대신 결과가 다른 3 세트를 반환합니다.
왜 그런가?
global $cat;
global $post;
$categories = get_categories('child_of=3');
foreach ($categories as $cat) :
$postslist = get_posts($cat->cat_ID, 'numberposts=1&order=DESC');
foreach ($postslist as $post) :
$option = '<li id="'.get_post_meta($post->ID, 'id', true).'">';
$option .='<a class="preview" rel="'.get_post_meta($post->ID, 'thumbnail', true).'" ';
$option .='href="'.get_bloginfo('url').'/'.$post->post_name.'">';
$option .=$cat->cat_name;
$option .='</a>';
$option .='</li>';
echo $option;
endforeach;
endforeach;