# 使用自定义帖子类型 #### 自定义帖子类型模板 您可以为自定义帖子类型创建自定义[模板。](https://make.wordpress.org/docs/theme-developer-handbook/theme-basics/theme-files/)`single.php`以与使用和显示帖子及其档案相同的方式`archive.php`,您可以创建模板: - `single-{post_type}.php`– 对于自定义帖子类型的单个帖子 - `archive-{post_type}.php`– 用于存档 其中`{post_type}`是 post 类型标识符,用作函数`$post_type`的参数`register_post_type()`。 根据我们之前学到的知识,您可以为单个产品帖子和存档创建模板文件`single-wporg_product.php`。`archive-wporg_product.php` 或者,您可以在任何模板文件中使用[is\_post\_type\_archive()](https://developer.wordpress.org/reference/functions/is_post_type_archive/) 函数来检查查询是否显示给定帖子类型的存档页面,并使用 post\_type\_archive\_title [()](https://developer.wordpress.org/reference/functions/post_type_archive_title/) 函数来显示帖子类型标题。 #### 按帖子类型查询 `post_type`您可以通过在类构造函数的参数数组中传递键来查询特定类型的帖子`WP_Query`。