WordPress函数get_post_format()获取文章的类型格式

描述:

获取文章的类型格式

用法:

<?php $format = get_post_format( $post_id ); ?>

参数:

$post_id

(integer) (可选) 文章ID

默认值: 当前循环的文章

源文件:

/**
 * 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 );
}