下吧资源网_专注精品网站源码下载的网站_免费商业源码分享

WordPress获取自定义文章类型分类法的所有文章循环

 

这篇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 }?>

本文链接:https://www.xiaba.cc/html/2061.html

版权声明:站内所有文章皆来自网络转载,只供模板演示使用,并无任何其它意义!

发表评论 共有 0 条评论)

联系客服
网站客服 业务合作 Q交流群
123456789
公众号
公众号
公众号
返回顶部