wordpress模板包含标签指的是在一个模板文件中包含另一个模板文件时涉及到的其它标签,在php中使用包含文件的函数是includeinclude_oncerequirerequire_once而在wordpress模板中包含另外一个模板使用了以下函数:get_header()get_footer()get_side

wordpress模板包含标签指的是在一个模板文件中包含另一个模板文件时涉及到的其它标签,在php中使用包含文件的函数是

includeinclude_oncerequirerequire_once

而在wordpress模板中包含另外一个模板使用了以下函数:

get_header()get_footer()get_sidebar()get_template_part()get_search_form()comments_template()

1、 get_header():包含头部模板用法:

<?php get_header(); ?>

说明:get_header() 标签包含了当前使用主题的头部模板文件: header.php 或者 header-{name}.php ,如果没有该文件则使用系统默认的头部模板文件: wp-includes/theme-compat/header.php 。

2、 get_footer():包含底部模板用法:

<?php get_footer(); ?>

说明:get_footer() 标签包含了当前使用主题的底部模板文件:footer.php 或者 footer-{name}.php ,如果没有该文件则使用系统默认的底部模板文件: wp-includes/theme-compat/footer.php.3、get_sidebar():包含侧边栏模板用法:

<?php get_sidebar(); ?>

说明:get_sidebar() 标签包含了当前使用主题的侧边栏模板文件:sidebar.php 或者 sidebar-{name}.php, 如果没有该文件则使用系统默认的侧边栏模板文件:wp-includes/theme-compat/sidebar.php。4、 get_template_part():包含自定义模板用法:

<?php get_template_part(); ?>

说明:get_template_part() 标签包含了当前使用主题的自定义的模板文件: {slug}.php 或者 {slug}-{name}.php。

5、 get_search_form():包含搜索框模板用法:

<?php get_search_form(); ?>

说明:get_search_form() 标签包含了当前使用主题的搜索框的模板文件: searchform.php ,如果没有该文件则使用系统生存默认的搜索框。

6、 comments_template():包含评论模板用法:

<?php comments_template(); ?>

comments_template() 标签包含了当前使用主题的评论的模板文件 comments.php, 如果没有该文件则使用系统默认的评论模板文件: wp-includes/theme-compat/comments.php。

标签应用实例

以下代码是一个简单的404页面模板实例,模板页面显示 “HTTP 404: Not Found”,主题中你可以将该文件命名为404.php。

<?php get_header(); ?><?php get_template_part('nav'); ?><h2>Error 404 - Not Found</h2><?php get_sidebar(); ?><?php get_footer(); ?>

模板参数

get_header(), get_footer() 和 get_sidebar() 接收以下的一个参数:

$name(string) (可选) 调用 sidebar-{name}.php 格式的模板文件。 例如: sidebar-right.php, header-single.php 或者 footer-8.php.默认: None

get_template_part() 接收以下两个参数:

$slug(string) (必须) 调用 {slug}.php格式的模板文件。例如: nav.php默认: None$name(string) (可选) 调用 {slug}-{name}.php格式模板文件。例如: nav-home.phpDefault: None

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。