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

目录

描述

Returns the post format of a post. This will usually be called in the the loop, but can be used anywhere if a post ID is provided.

get_post_format() 描述

用法

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

get_post_format() 用法

参数

$post_id

(integer) (可选) ID of the post.

默认值: current loop post

get_post_format() 参数

源文件

get_post_format() 函数的代码位于 wp-includes/post-formats.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * 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 );
}

get_post_format() 源文件

相关