我有一个Wordpress数据库,分为三类:
ID 3:欧洲
ID 4:法国(3岁的孩子)
ID 5:巴黎(4岁的孩子)
我现在需要显示其各自类别下的所有帖子,如下所示:
欧洲1号岗位2号岗位3号岗位
法国,1号岗位,3号岗位
巴黎邮政3
第1篇是在法国发表的,第2篇是在欧洲发表的,第3篇是在巴黎发表的,你能确认我这样做是对的吗?
<?php
$args = array(\'cat\' => 3);
$category_posts = new WP_Query($args);
?>
<!-- Show EUROPE block, so just loop, no check -->
<?php
while($category_posts->have_posts()) : $category_posts->the_post();
the_title("<br />");
endwhile;
?>
<!-- Show FRANCE block, check category name -->
<?php
while($category_posts->have_posts()) : $category_posts->the_post();
if (strpos(get_the_category()[0]->cat_name,\'France\') !== false)
the_title("<br />");
endwhile;
?>
<!-- Show PARIS block, check category name -->
<?php
while($category_posts->have_posts()) : $category_posts->the_post();
if (strpos(get_the_category()[0]->cat_name,\'Paris\') !== false)
the_title("<br />");
endwhile;
?>
上述代码中省略了HTML格式用蹩脚的话来说,我只调用了一次WP\\u查询,然后我循环,检查法国和巴黎块的类别名称“France”和“Paris”。有更好的方法吗?如果我调用WP\\u Query三次,是否会导致性能问题?非常感谢。