is_post_type_archive()判断当前的文章是否为某个类型

目录

描述

Checks if the query is for an archive page of a given post type(s).

is_post_type_archive() 描述

用法

<?php is_post_type_archive$post_types ); ?>

is_post_type_archive() 用法

参数

$post_types

(array/string) (可选) Post type or array of posts types to check against.

默认值: None

is_post_type_archive() 参数

返回值

(boolean

Whether the query is for an archive page of a given post type(s).

is_post_type_archive() 返回值

示例

Determine if the current page is an archive made by a custom post type and display the custom post type title:

is_post_type_archive() 示例

注意

This returns false for a page like /category/uncategorized/?post_type=custom. It only returns true for a page like /?post_type=custom. In other words, it's not checking for the existence of the post_type query parameter, it's testing if this is the archive of all posts of a given type. You might instead be looking for get_query_var('post_type').

Depending on when this function is run it may or may not be run by nav_menu_item. Take the following code example:

"Do stuff" may or may not be run in the menu, depending on if the theme is using nav menus or not. The correct usage would be:

is_post_type_archive() 注意

历史

  • 添加于 版本: 3.1.0

is_post_type_archive() 历史

源文件

is_post_type_archive() 函数的代码位于 wp-includes/query.php.

is_post_type_archive() 源文件

相关