这应该行得通。我修改了你的$args
在while(have_posts()) : the_post();
循环,然后添加the_post_thumbnail()
功能,最后wp_query_reset();
在底部:
<?php
$limit = 999;
$counter = 0;
$categories = get_categories();
foreach ( $categories as $category ):
if ( $counter < $limit ) {
$args = array(
\'posts_per_page\' => 1,
\'cat\' => $category->cat_ID,
\'ignore_sticky_posts\' => 1
);
$posts = get_posts( $args );
while( have_posts() ) : the_post();
echo \'<div class="category">\';
the_post_thumbnail();
echo \'<a href="\' . get_category_link($category->term_id) . \'" title="\' . sprintf(__("View all posts in %s"), $category->name) . \'" \' . \'>\';
echo \'<h3>\' . $category->name . \'</h3>\';
echo \'</a>\';
echo \'</div>\';
endwhile;
}
$counter++;
endforeach;
wp_query_reset();
?>
Ps。
caller_get_posts
自版本3.1以来已弃用!使用
ignore_sticky_posts
而是在您的
$args