我已经创建了下面的函数,该函数用于列出id为3的父类的子类别。
该函数还应返回每个子类别中第一个帖子的元数据。
这是可行的(有点),但它不是只获得一组数据,而是返回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;发布于 2009-06-07 19:07:17
我已经知道我错在哪里了!这一点:
$postslist = get_posts($cat->cat_ID, 'numberposts=1&order=DESC');已替换为:
$postslist = get_posts('category='.$cat->cat_ID.'numberposts=1&order=DESC');这给出了实际的类别id。
发布于 2009-06-07 19:13:34
如果您查看get_posts()的wordpress.org文档,您会发现该函数只有一个参数。
get_posts('numberposts=1&category='. $cat->cat_ID .'&order=DESC');https://stackoverflow.com/questions/962445
复制相似问题