您的当前位置:首页 > 知识博客 > wordpress建站

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

时间:2024-03-13

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

相关函数:

  • get_post()

  • get_post_types()


欢迎咨询/Welcome to inquire
tel/vx:18842938855
qq:1685522781
email:1685522781@qq.com

Copyright © 2019-2024 asp.cyou


Whatsapp
Powered by RRZCMS