Php 在wordpress中自动获取分类法的所有类别名称

Php 在wordpress中自动获取分类法的所有类别名称,php,wordpress,add,Php,Wordpress,Add,我必须为一个朋友做一个项目,我需要知道是否有可能在wordpress中以友好方式检索分类法的所有类别名称。如果有可能,我该怎么做?是的,你可以!首先在function.php文件末尾添加以下代码: function current_cat() { global $post; if ( is_page() && $post->post_parent ) $childpages = wp_list_pages( 'sort_column=menu_o

我必须为一个朋友做一个项目,我需要知道是否有可能在wordpress中以友好方式检索分类法的所有类别名称。如果有可能,我该怎么做?

是的,你可以!首先在function.php文件末尾添加以下代码:

function current_cat() { 
    global $post;
    if ( is_page() && $post->post_parent )
     $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' . '&depth=1' );
      else
      $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' . '&depth=1' );
    if ( $childpages ) {
    $string = '<ul>' . $childpages . '</ul>';
    }
    return $string;
}
add_shortcode('currentcat', 'current_cat');

只需使用此函数get_terms()


为了获得更多参考,本教程可能会帮助您

您是否已经在论坛上搜索过?因为有很多类似于你的问题。我已经搜索过了,但还没有找到我的范围的具体答案。查看此线程了解更多信息:我不明白我必须在属性:字段和术语中添加什么。我不明白这两者之间的区别谢谢,太好了!一个问题:有没有可能用get_术语来做这件事?没问题。我没有在这个案子上尝试过。但是我在这个网站上使用了这个短代码,效果很好,你可以在帖子上面看到当前菜单的类别:我想利用你的礼貌:):)可以这样做吗:terms=>all…用tax_查询检索所有类别?
 [currentcat]
$taxonomies = get_terms( array(
    'taxonomy' => 'taxonomy_name'
) );

if ( !empty($taxonomies) ) :
    foreach( $taxonomies as $category ) {
      print_r($category);
    }
endif;