我在wordpress中创建了一个网站......我的要求是我在主页上每个类别都需要一个帖子..
以下是我的PHP代码:
$args = array('type' => 'post', 'orderby' => 'name', 'order' => 'ASC', 'number' => '10', 'taxonomy' => 'category');
$categories = get_categories($args);
foreach($categories as $category) {
$catquery = new WP_Query( 'cat='.$category->cat_ID.'&order=DESC' );
while($catquery->have_posts()) : $catquery->the_post();
echo "Some div & links";
endwhile;
}
上面的代码给了我所有类别的所有帖子...如何获得每个类别中唯一的1个最新帖子?? ??
Wat我应该改变上面的代码.. ???请让我知道......
答案 0 :(得分:0)
我已经解决了这个问题..请检查以下代码
$args = array('type' => 'post', 'orderby' => 'name', 'order' => 'ASC', 'number' => '10', 'taxonomy' => 'category');
$categories = get_categories($args);
foreach($categories as $category) {
$catquery = new WP_Query( 'cat='.$category->cat_ID.'&order=DESC' );
$catquery->the_post();
echo "Some div & links";
}
我刚刚删除while循环...:)