^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_query_template()用法示例

get_query_template( string $type,  array $templates = array() )

Retrieve path to a template


描述

Used to quickly retrieve the path of a template without including the file extension. It will also check the parent theme, if the file exists, with the use of locate_template(). Allows for more generic template location without the use of the other get_*_template() functions.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包


参数

$type

(string)
(Required)
Filename without extension.

$templates

(array)
(Optional)
An optional list of template candidates

Default value: array()


返回值

(string) Full path to template file.


源代码

File: wp-includes/template.php

function get_query_template( $type, $templates = array() ) {
	$type = preg_replace( '|[^a-z0-9-]+|', '', $type );

	if ( empty( $templates ) )
		$templates = array("{$type}.php");

	/**
	 * Filters the list of template filenames that are searched for when retrieving a template to use.
	 *
	 * The last element in the array should always be the fallback template for this query type.
	 *
	 * Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date',
	 * 'embed', home', 'frontpage', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'.
	 *
	 * @since 4.7.0
	 *
	 * @param array $templates A list of template candidates, in descending order of priority.
	 */
	$templates = apply_filters( "{$type}_template_hierarchy", $templates );

	$template = locate_template( $templates );

	/**
	 * Filters the path of the queried template by type.
	 *
	 * The dynamic portion of the hook name, `$type`, refers to the filename -- minus the file
	 * extension and any non-alphanumeric characters delimiting words -- of the file to load.
	 * This hook also applies to various types of files loaded as part of the Template Hierarchy.
	 *
	 * Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date',
	 * 'embed', home', 'frontpage', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'.
	 *
	 * @since 1.5.0
	 * @since 4.8.0 The `$type` and `$templates` parameters were added.
	 *
	 * @param string $template  Path to the template. See locate_template().
	 * @param string $type      Filename without extension.
	 * @param array  $templates A list of template candidates, in descending order of priority.
	 */
	return apply_filters( "{$type}_template", $template, $type, $templates );
}

更新日志

Version 描述
1.5.0 Introduced.

相关函数

Uses

  • wp-includes/template.php:
    {$type}_template_hierarchy
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/template.php:
    locate_template()
  • wp-includes/template.php:
    {$type}_template

Used By

  • wp-includes/template.php:
    get_embed_template()
  • wp-includes/template.php:
    get_singular_template()
  • wp-includes/template.php:
    get_search_template()
  • wp-includes/template.php:
    get_single_template()
  • wp-includes/template.php:
    get_attachment_template()
  • wp-includes/template.php:
    get_index_template()
  • wp-includes/template.php:
    get_404_template()
  • wp-includes/template.php:
    get_archive_template()
  • wp-includes/template.php:
    get_author_template()
  • wp-includes/template.php:
    get_category_template()
  • wp-includes/template.php:
    get_tag_template()
  • wp-includes/template.php:
    get_taxonomy_template()
  • wp-includes/template.php:
    get_date_template()
  • wp-includes/template.php:
    get_home_template()
  • wp-includes/template.php:
    get_front_page_template()
  • wp-includes/template.php:
    get_page_template()
  • wp-includes/deprecated.php:
    get_paged_template()
  • Show 12 more used by
    Hide more used by


  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Example

    Can be used with include() or require() to retrieve path.

    
    if ( '' !== get_query_template( '404' ) ) {
    	include( get_query_template( '404' ) );
    }
    

    or the same can be accomplished with

    
    if ( '' != get_404_template() ) {
    	include( get_404_template() );
    }
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈