显示与当前帖子相同的子分类的帖子

时间:2015-06-04 10:32:29

标签: wordpress

我正在学习本教程

https://sridharkatakam.com/custom-wordpress-widget-showing-cpt-entries-categorycategories/

我有两个自定义分类法(事件/中心),以及各自的子分类法(event1, event2… / center1, center2…)。

我应该更改以显示与当前帖子相同的子分类中的帖子? (一个帖子可以使用一个eventschild taxonomy,一个中心儿童分类,或两者兼而有之。)

我只是希望它与taxonomy匹配,我不使用任何类别。

我必须使用什么而不是这些?

get_the_category()
category_nicename

不介意是否使用此方法

https://sridharkatakam.com/show-posts-category-current-post/

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

<?php

//first get the current term
$current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

//then set the args for wp_list_categories
 $args = array(
    'child_of' => $current_term->term_id,
    'taxonomy' => $current_term->taxonomy,
    'hide_empty' => 0,
    'hierarchical' => true,
    'depth'  => 1,
    'title_li' => ''
 );
 wp_list_categories( $args );
?>

^^这就是我多年前做驴的方式:)

相关问题