首页 > wordperss合并多个相同数据请求

wordperss合并多个相同数据请求

Hi,
我的网站采用wordpress,首页index.php里面使用下面的代码来输出不同分类下面对应文章,分类是采用自定义分类法,
由于我需要输出多个不同分类的内容(以列表的形式表现),我现在的做法是把下面的代码复制了10遍,去输出对应分类,想请教下大家php里面怎样合并这个请求?
网上找资料说可以把数据储存在数组里面,然后调用,没搞定,希望有朋友能帮助我

谢谢!

<?php 
    $args = array(
      'post_type' => 'post', //自定义文章类型名称
      'showposts' => 3, //输出的文章数量,这个可以是缺省值,不用设置                                     
      'posts_per_page' => 1,//筛选分类置顶文章
      'post__in'  => get_option( 'sticky_posts' ),//筛选分类置顶文章
      'ignore_sticky_posts' => 1,//筛选分类置顶文章
      'tax_query' => array(
                          array(
                               'taxonomy' => 'area_usa',//自定义分类法名称
                               'terms' => array(7), //id为7的分类。提问所指的分类就是这个?
                               ),
                           )
                 );
    $my_query = new WP_Query($args);
       if( $my_query->have_posts() ) {
          while ($my_query->have_posts()) :     $my_query->the_post();?>

    <?php get_template_part( 'home', 'list' ); ?>
    <?php endwhile; wp_reset_query(); //重置query查询
    }
?>

可以自己写函数或者用简码实现,我开发过一个实现类似功能的插件,还在完善中,可以参考一下,https://wordpress.org/plugins/wizhi-cms/

【热门文章】
【热门文章】