load_template()加载自定义的模版文件

目录

描述

译文

在WordPress环境中命令模板文件。

为模板文件设置全局变量以确保函数在WordPress环境内可用。查询变量也可用。

原文

Require once the template file with WordPress environment.

The globals are set up for the template file to ensure that the WordPress environment is available from within the function. The query variables are also available.

load_template() 描述

用法

<?php load_template$_template_file$require_once ?>

load_template() 用法

参数

$_template_file

(string) (必填) Path to template file.

默认值: None

$require_once

(bool) (可选) Whether to require_once or require.

默认值: true

load_template() 参数

返回值

(void) 

This function does not return a value.

load_template() 返回值

示例

Loading a template in a plugin, but allowing theme and child theme to override template

load_template() 示例

注意

  • 使用到 global: (object) $wp_query to extract extract() global variables returned by the query_vars method while protecting the current values in these global variables:
    • (unknown type) $posts
    • (unknown type) $post
    • (boolean) $wp_did_header Returns true if the WordPress header was already loaded. See the /wp-blog-header.php file for details.
    • (boolean) $wp_did_template_redirect
    • (object) $wp_rewrite
    • (object) $wpdb
    • (string) $wp_version holds the installed WordPress version number.
    • (string) $wp
    • (string) $id
    • (string) $comment
    • (string) $user_ID

load_template() 注意

历史

添加于 版本: 1.5.0

load_template() 历史

源文件

load_template() 函数的代码位于 wp-includes/template.php.

load_template() 源文件

相关