在 Wordpress 中每个类别需要一个 Post
Require One Post per Category in Wordpress
我在 wordpress 中创建了一个网站...我的要求是主页上每个类别需要一个 post..
下面是我在 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;
}
上面的代码给出了所有类别中的所有 post...如何获得每个类别中唯一的 1 个最新的 post..??
我应该在上面的代码中更改什么..???请告诉我...
我已经解决了这个问题..请检查下面的代码
$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 循环...:)
我在 wordpress 中创建了一个网站...我的要求是主页上每个类别需要一个 post..
下面是我在 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;
}
上面的代码给出了所有类别中的所有 post...如何获得每个类别中唯一的 1 个最新的 post..??
我应该在上面的代码中更改什么..???请告诉我...
我已经解决了这个问题..请检查下面的代码
$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 循环...:)