Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在博客页面(帖子页面)上显示类别名称_Php_Wordpress_Wordpress Theming_Categories_Custom Wordpress Pages - Fatal编程技术网

Php 如何在博客页面(帖子页面)上显示类别名称

Php 如何在博客页面(帖子页面)上显示类别名称,php,wordpress,wordpress-theming,categories,custom-wordpress-pages,Php,Wordpress,Wordpress Theming,Categories,Custom Wordpress Pages,大家好,我希望你们做得很好,我在如何在帖子页面或我的博客页面上显示类别名称方面遇到了问题,有人能告诉我如何显示类别名称吗 下面是它的外观(红色矩形是类别名称): 谢谢您必须使用get_terms()函数来获取该特定分类法的所有类别 $terms = get_terms( 'my_taxonomy' ); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ echo '<ul>'; foreach

大家好,我希望你们做得很好,我在如何在帖子页面或我的博客页面上显示类别名称方面遇到了问题,有人能告诉我如何显示类别名称吗

下面是它的外观(红色矩形是类别名称):



谢谢

您必须使用
get_terms()
函数来获取该特定分类法的所有类别

$terms = get_terms( 'my_taxonomy' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
    echo '<ul>';
    foreach ( $terms as $term ) {
        echo '<li>' . $term->name . '</li>';
    }
    echo '</ul>';
$terms=get_terms('my_taxonomy');
如果(!empty($terms)&&!is_wp_error($terms)){
回声“
    ”; foreach($terms作为$term){ 回显“
  • ”.$term->name.“
  • ”; } 回声“
”;
这里
myu分类法
将是您的分类法或类别名称

参考:

$terms = get_terms( 'my_taxonomy' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
    echo '<ul>';
    foreach ( $terms as $term ) {
        echo '<li>' . $term->name . '</li>';
    }
    echo '</ul>';