0
在WordPress category.php我有這樣的代碼:減少和乾淨的代碼
if (is_category('cat-1')) {
$the_query = new WP_Query(array ('post_type' => 'mueble', 'category_name' => 'cat-1' , 'posts_per_page' => 3)) ;
}
if (is_category('cat-2')) {
$the_query = new WP_Query(array ('post_type' => 'mueble', 'category_name' => 'cat-2' , 'posts_per_page' => 3)) ;
}
if (is_category('cat-3')) {
$the_query = new WP_Query(array ('post_type' => 'mueble', 'category_name' => 'cat-3' , 'posts_per_page' => 3)) ;
}
while ($the_query->have_posts()) : $the_query->the_post();
...
endwhile; wp_reset_postdata();
我怎麼能簡化代碼?我有30個類別和太多的條件語句不理想......