这篇WordPress教程思路来源于WordPress技术:923323423,*内大佬魏星的帮助。
用魏大佬的话来说就是 :
1.先调出所有分类咯 2.然后循环套循环 3.完事儿
这可能对WordPress大神来说确实不是什么难点,但是对于咱们这些WordPress初学者来说,还是需要点时间琢磨的。
经过一阵研究也终于初步研究出来,不过百度似乎也有类似的WordPress代码,下面贴出我写的代码,大神不要见笑。。
<?php $args=array( \'taxonomy\' => \'sitecat\', \'hide_empty\'=>\'0\', \'hierarchical\'=>1, \'parent\'=>\'0\', ); $categories=get_categories($args); foreach($categories as $category){ $cat_id = $category->term_id; ?> //第一个循环为获取所有自定义文章类型的分类法。$cat_id <?php $salong_posts = new WP_Query( array( \'post_type\' => \'site\',//自定义文章类型,这里为site \'ignore_sticky_posts\' => 1,//忽略置顶文章 \'posts_per_page\' => 8,//显示的文章数量 \'tax_query\' => array( array( \'taxonomy\' => \'sitecat\',//自定义文章类型的分类法名称 \'field\' => \'id\', \'terms\' => $cat_id,//分类法ID ) ), ) ); if ($salong_posts->have_posts()): while ($salong_posts->have_posts()): $salong_posts->the_post(); ?> //循环内容 <?php the_title(); ?> <?php endwhile; endif; ?> //第二个循环为获取所有分类法的文章循环 <?php }?>