markdown 有用的WordPress分类功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 有用的WordPress分类功能相关的知识,希望对你有一定的参考价值。

## [`get_the_category( int $id = false )`](https://developer.wordpress.org/reference/functions/get_the_category/)   
Retrieve post categories, but only for the default taxonomy. If you're using it inside a post, the post ID is not necessary.

#### Example:   
```
$temp = get_the_category( $post->ID );
var_dump($temp);
```

#### Output:
```
array (size=1)
  0 => 
    object(WP_Term)[1438]
      public 'term_id' => int 1
      public 'name' => string 'Uncategorized' (length=13)
      public 'slug' => string 'uncategorized' (length=13)
      public 'term_group' => int 0
      public 'term_taxonomy_id' => int 1
      public 'taxonomy' => string 'category' (length=8)
      public 'description' => string '' (length=0)
      public 'parent' => int 0
      public 'count' => int 2
      public 'filter' => string 'raw' (length=3)
      public 'cat_ID' => int 1
      public 'category_count' => int 2
      public 'category_description' => string '' (length=0)
      public 'cat_name' => string 'Uncategorized' (length=13)
      public 'category_nicename' => string 'uncategorized' (length=13)
      public 'category_parent' => int 0
```

## [`get_the_terms( int|object $post, string $taxonomy )`](https://developer.wordpress.org/reference/functions/get_the_terms/)   
Retrieve post categories for any taxonomy. Generates an array of arrays with information on each term in the selected taxonomy for that post.

#### Example:
```
$temp = get_the_terms( $post->ID, 'threats' );
var_dump($temp);
```
#### Output:
```
array (size=2)
  0 => 
    object(WP_Term)[1438]
      public 'term_id' => int 11
      public 'name' => string 'Digital' (length=7)
      public 'slug' => string 'digital' (length=7)
      public 'term_group' => int 0
      public 'term_taxonomy_id' => int 11
      public 'taxonomy' => string 'threats' (length=7)
      public 'description' => string '' (length=0)
      public 'parent' => int 0
      public 'count' => int 2
      public 'filter' => string 'raw' (length=3)
  1 => 
    object(WP_Term)[1364]
      public 'term_id' => int 12
      public 'name' => string 'Financial' (length=9)
      public 'slug' => string 'financial' (length=9)
      public 'term_group' => int 0
      public 'term_taxonomy_id' => int 12
      public 'taxonomy' => string 'threats' (length=7)
      public 'description' => string '' (length=0)
      public 'parent' => int 0
      public 'count' => int 1
      public 'filter' => string 'raw' (length=3)
```

## [`get_the_term_list( int $id, string $taxonomy, string $before = '', string $sep = '', string $after = '' )`](https://developer.wordpress.org/reference/functions/get_the_term_list/)   
Retrieve a post’s terms as an html encoded list of links with specified separators.

#### Example:   
```
$temp = get_the_term_list( $post->ID, 'threats', '', ', ', '' );
var_dump($temp);
```

#### Output:   
```
/Sites/eri/wp-content/themes/radicati-eri/single.php:71:string '<a href="http://eri.test/?taxonomy=threats&#038;term=digital" rel="tag">Digital</a>, <a href="http://eri.test/?taxonomy=threats&#038;term=financial" rel="tag">Financial</a>' (length=172)
```

以上是关于markdown 有用的WordPress分类功能的主要内容,如果未能解决你的问题,请参考以下文章

markdown 有用的WordPress插件片段

markdown WordPress中的自定义帖子类型和分类

markdown WordPress中的自定义帖子类型和分类

markdown 在twig文件中使用WordPress功能

markdown 实现Twitter Bootstrap di WordPress主题melalui主题的功能文件。

php 有用的Wordpress功能1