描述:
判断当前的文章是否为某个类型
用法:
<?php is_post_type_archive( $post_types ); ?>
参数:
$post_types
(array/string) (可选) 要判断的post_type可以是一个也可以是数组.
默认值: None
示例:
<?php
if ( is_post_type_archive() ) {
?>
<h1><?php post_type_archive_title(); ?></h1>
<?php
}
?>
源文件:
/**
* Is the query for an existing post type archive page?
*
* @since 3.1.0
*
* @global WP_Query $wp_query
*
* @param string|array $post_types Optional. Post type or array of posts types to check against.
* @return bool
*/
function is_post_type_archive( $post_types = '' ) {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
return false;
}
return $wp_query->is_post_type_archive( $post_types );
}