get_post_format()
最后更新于:2021-11-26 22:30:55
get_post_format( int|GC_Post|null$post=null)Retrieve the format slug for a post
参数
- $post
-
(int|GC_Post|null) (Optional) Post ID or post object. Defaults to the current post in the loop.
Default value: null
响应
(string|false) The format if successful. False otherwise.
源文件
文件: gc-includes/post-formats.php
function get_post_format( $post = null ) {
$post = get_post( $post );
if ( ! $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 );
}