描述:

检索目前文章或给定文章的文章类型。

用法:

<?php echo get_post_type( $post ) ?>

参数:

$post

(mixed) (可选) Post对象或Post ID。如果为空,将使用当前Post。

默认值: null

示例:

<?php echo 'The post type is: ' . get_post_type( get_the_ID() ); ?>

源文件:

/**
 * Retrieve the post type of the current post or of a given post.
 *
 * @since 2.1.0
 *
 * @param int|WP_Post|null $post Optional. Post ID or post object. Default is global $post.
 * @return string|false          Post type on success, false on failure.
 */
function get_post_type( $post = null ) {
	if ( $post = get_post( $post ) )
		return $post->post_type;

	return false;
}

 

参与评论