get_post_format()
get_post_format( int|object|null $post = null ) 检索帖子的格式…
get_post_format( int|object|null $post = null )
检索帖子的格式段塞
Retrieve the format slug for a post
目录锚点:#参数#返回#源码#笔记
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $post | (int | object | null) | 可选 | Post ID或Post对象。可选,默认值是来自循环的当前post。 |
返回(Return)
(string|false)成功时的格式。否则就错了。
源码(Source)
/**
* Retrieve the format slug for a post
*
* @since 3.1.0
*
* @param int|object|null $post Post ID or post object. Optional, default is the current post from the loop.
* @return string|false The format if successful. False otherwise.
*/
function get_post_format( $post = null ) {
if ( ! $post = get_post( $post ) )
return false;
if ( ! post_type_supports( $post->post_type, 'post-formats' ) )
return false;
$_format = get_the_terms( $post->ID, 'post_format' );
if ( empty( $_format ) )
return false;
$format = reset( $_format );
return str_replace('post-format-', '', $format->slug );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 3.1.0 | wp-includes/post-formats.php:17 | 10 | 3 |
笔记(Notes)
模板中的使用
例子
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。





还没有任何评论,赶紧来占个楼吧!