wpseek.com
WordPress开发者和主题制作者的搜索引擎



is_page_template › WordPress Function

Since2.5.0
已弃用n/a
is_page_template ( $template = '' )
参数:
  • (string|string[]) $template The specific template filename or array of templates to match.
    Required: No
    默认: (empty)
返回:
  • (bool) True on success, false on failure.
定义在:
文档:
Change Log:
  • 4.2.0
  • 4.7.0

Determines whether the current post uses a page template.

This template tag allows you to determine if you are in a page template. You can optionally provide a template filename or array of template filenames and then the check will be specific to that template. For more information on this and similar theme functions, check out the {@link Conditional Tags} article in the Theme Developer Handbook.


源码

function is_page_template( $template = '' ) {
	if ( ! is_singular() ) {
		return false;
	}

	$page_template = get_page_template_slug( get_queried_object_id() );

	if ( empty( $template ) ) {
		return (bool) $page_template;
	}

	if ( $template == $page_template ) {
		return true;
	}

	if ( is_array( $template ) ) {
		if ( ( in_array( 'default', $template, true ) && ! $page_template )
			|| in_array( $page_template, $template, true )
		) {
			return true;
		}
	}

	return ( 'default' === $template && ! $page_template );
}