2009-06-07 7 views
0

는 또한 각 서브 카테고리의 첫 포스트로부터 메타 데이터를 반환한다 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; 

답변

0

나는 어디서 잘못되었는지 알아 냈습니다! 이 :

$postslist = get_posts('category='.$cat->cat_ID.'numberposts=1&order=DESC'); 

이 실제 카테고리 ID를 제공합니다

$postslist = get_posts($cat->cat_ID, 'numberposts=1&order=DESC'); 

가로 대체되었습니다.

1

wordpress.org의 문서를 get_posts()으로 보면이 함수에는 인수가 하나만 있음을 알 수 있습니다.

get_posts('numberposts=1&category='. $cat->cat_ID .'&order=DESC');