wordpress建站wordpress教程_WordPress如何在子分类获取父分类的链接
上一篇文章代码农给人人分享了若何获取自定义文章类型下的分类法名称、 分类法链接以及分类法ID这篇文章我们就来了解下WordPress若何获取自定义文章类型下的所有分类法以及分类法中的所有文章循环。
这篇WordPress教程思绪来源于WordPress手艺:
用魏大佬的话来说就是 :
wordpress教程wordpress错误_WordPress移除head头部js、css、feed等多余加载项
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 }?>