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

wordpress函数get_single_template()用法示例

get_single_template()

Retrieve path of single template in current or parent template. Applies to single Posts, single Attachments, and single custom post types.


描述

The hierarchy for this template looks like:

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

  1. {Post Type Template}.php
  2. single-{post_type}-{post_name}.php
  3. single-{post_type}.php
  4. single.php

An example of this is:

  1. templates/full-width.php
  2. single-post-hello-world.php
  3. single-post.php
  4. single.php

The template hierarchy and template path are filterable via the ‘$type_template_hierarchy’ and ‘$type_template’ dynamic hooks, where $type is ‘single’.


返回值

(string) Full path to single template file.


源代码

File: wp-includes/template.php

function get_single_template() {
	$object = get_queried_object();

	$templates = array();

	if ( ! empty( $object->post_type ) ) {
		$template = get_page_template_slug( $object );
		if ( $template && 0 === validate_file( $template ) ) {
			$templates[] = $template;
		}

		$name_decoded = urldecode( $object->post_name );
		if ( $name_decoded !== $object->post_name ) {
			$templates[] = "single-{$object->post_type}-{$name_decoded}.php";
		}

		$templates[] = "single-{$object->post_type}-{$object->post_name}.php";
		$templates[] = "single-{$object->post_type}.php";
	}

	$templates[] = "single.php";

	return get_query_template( 'single', $templates );
}

更新日志

Version 描述
4.7.0 Post Type Template}.php was added to the top of the template hierarchy
4.4.0 single-{post_type}-{post_name}.php was added to the top of the template hierarchy.
1.5.0 Introduced.

相关函数

Uses

  • wp-includes/query.php:
    get_queried_object()
  • wp-includes/functions.php:
    validate_file()
  • wp-includes/template.php:
    get_query_template()
  • wp-includes/post-template.php:
    get_page_template_slug()

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

热门推荐

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

反馈