WordPress根据文章ID获取文章类型函数:get_post_type

WordPress函数get_post_type获取当前文章或指定文章的文章类型,在The Loop主循环中使用则不需要传递文章ID。

get_post_type( int|WP_Post|null $post = null )

函数参数

$post

整数或WP_Post对象

传递文章ID或WP_Post对象

函数使用示例

$post_id = get_the_ID();
if ( get_post_type( $post_id ) == 'page' ) {
	echo "文章{$post_id}的类型为page";
}

扩展阅读

get_post_type()函数位于:wp-includes/post.php

相关函数:

原创文章,作者:,如若转载,请注明出处:https://ce.771633.xyz/1822.html

Like (0)
Previous 2025年3月8日
Next 2025年3月8日

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注