wp_get_post_categories()
wp_get_post_categories( int $post_id, array $args = arr…
wp_get_post_categories( int $post_id, array $args = array() )
检索文章的类别列表。
Retrieve the list of categories for a post.
检索文章的类别列表。
Retrieve the list of categories for a post.
目录锚点:#说明#参数#源码#笔记
说明(Description)
主题和插件的兼容性层。也是一个简单的抽象层,远离了分类层的复杂性。另请参阅wp_get_object_terms()
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $post_id | (int) | Post ID.不默认为全局$Post的ID。默认值为0。 |
| $args | (array) | 类别查询参数。有关支持的参数,请参见WP_Term_Query::uu construct()。 |
源码(Source)
/**
* Retrieve the list of categories for a post.
*
* Compatibility layer for themes and plugins. Also an easy layer of abstraction
* away from the complexity of the taxonomy layer.
*
* @since 2.1.0
*
* @see wp_get_object_terms()
*
* @param int $post_id Optional. The Post ID. Does not default to the ID of the
* global $post. Default 0.
* @param array $args Optional. Category arguments. Default empty.
* @return array List of categories.
*/
function wp_get_post_categories( $post_id = 0, $args = array() ) {
$post_id = (int) $post_id;
$defaults = array('fields' => 'ids');
$args = wp_parse_args( $args, $defaults );
$cats = wp_get_object_terms($post_id, 'category', $args);
return $cats;
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.1.0 | wp-includes/post.php | 16 | 4 |
笔记(Notes)
下面的示例显示了如何检索类别,然后为每个类别检索附加信息。
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!