HI,欢迎来到我爱模板网!

wordpress模板包含标签使用介绍

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

给TA打赏
共{{data.count}}人
人已打赏
wordpress教程

如何充分利用您的 WordPress 子主题

2022-12-31 23:45:53

wordpress教程

自定义WordPress后台样式风格

2022-12-31 23:45:55

【腾讯云】11.11云上盛惠!云服务器首年1.8折起,买1年送3个月!
11.11云上盛惠!海量产品·轻松上云!云服务器首年1.8折起,买1年送3个月!超值优惠,性能稳定,让您的云端之旅更加畅享。
查看更多相关信息>>
站长

(工作日 10:00 - 22:30 为您服务)

2026-01-30 05:36:29

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

猜你想问:

  • 购买的模板免费包安装吗?

  • 这个演示地址有吗?

  • 购买vip会员可以下载哪些模板?

您的留言我们已经收到,我们将会尽快跟您联系!
取消
立即选择任一渠道联系我们