有时需要在WordPress分类归档页面显示当前分类子分类链接,可以用下面的代码:
$args=array( 'child_of' => get_query_var( 'cat' ), 'hide_empty' => 0, 'orderby' => 'ID', 'order' => 'ASC' ); $categories=get_categories( $args ); foreach( $categories as $category ) { echo '<a href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a>'; }
其中:文章源自知更鸟-https://zmingcx.com/wordpress-displays-subcategories.html
'hide_empty' => 参数为1时,不显示没有文章的空分类。文章源自知更鸟-https://zmingcx.com/wordpress-displays-subcategories.html
如只想显示一级子分类,可以加上参数'parent' => 1,文章源自知更鸟-https://zmingcx.com/wordpress-displays-subcategories.html 文章源自知更鸟-https://zmingcx.com/wordpress-displays-subcategories.html
本站文章大部分始于原创,用于个人学习记录,可能对您有所帮助,仅供参考!

我的微信
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
湖南省株洲市 1F
能不能出个列表后只显示指定时间范围内文章。
中国 B1
@ 六六社 写了段代码,看我博客最新文章