wordpress 主题/模板文件说明
技术 2025年12月03日 作者: 管振佐
140 阅读 0 评论

wordpress 主题/模板文件说明

常用WordPress模板文件

以下是WordPress可以识别的一些主题模板和文件列表。

  • index.php:主模板文件,所有主题都需要这个文件。
  • style.css:主样式文件,包含主题的信息,所有主题都需要这个文件。
  • rtl.css:从右向左阅读的样式文件,如果站点语言是从右向左阅读的,主题会自动包含此文件。
  • comments.php:主题评论模板文件。
  • front-page.php:首页模板文件,无论阅读设置中的首页设置为什么总是,优先选择此文件模板作为首页模板文件。
  • home.php:如果阅读设置中设置为静态页面,选择此文件作为首页模板文件。
  • header.php:网站页头模板文件,通常包含您网站的文档类型、元信息、样式表、脚本链接以及其他数据。
  • singular.php:单页面模板,未找到 single.php 或 page.php 时,使用此文件作为这些文章类型的单页面模板文件。
  • single.php:「文章」的详情页模板文件。
  • single-{post-type}.php:「post-type」文章类型的详情页模板文件。
  • archive-{post-type}.php:「post-type」文章类型的存档页模板文件。
  • page.php:「页面」文章类型的详情页模板文件。
  • page-{slug}.php:别名为「slug」的页面详情页模板文件。
  • category.php:分类目录存档模板文件。
  • tag.php:标签存档模板文件。
  • taxonomy.php:自定义分类法存档模板文件。
  • author.php:作者存档页模板文件。
  • date.php:日期存档页模板文件。
  • archive.php:默认存档页默模板文件。
  • search.php:搜索结果页模板文件。
  • attachment.php:单个附件页面模板文件。
  • image.php:图像页面模板文件。
  • 404.php:页面找不到时,显示的 404 错误页面模板文件。

使用模板文件

在WordPress模板中,您可以使用模板标签动态显示信息,包括其他模板文件或以其他方式自定义您的网站。

例如,您可以在 index.php 中包含其他文件:

  • 要包含页眉,请使用<a href="https://developer.wordpress.org/reference/functions/get_header/" target="_blank" rel="noreferrer noopener" aria-label="(在新窗口打开)">get_header()</a>
  • 要包含侧边栏,请使用<a href="https://developer.wordpress.org/reference/functions/get_sidebar/" target="_blank" rel="noreferrer noopener" aria-label="get_sidebar()(在新窗口打开)">get_sidebar()</a>
  • 要包含页脚,请使用<a href="https://developer.wordpress.org/reference/functions/get_footer/" target="_blank" rel="noreferrer noopener" aria-label="get_footer()(在新窗口打开)">get_footer()</a>
  • 要包含搜索表单,请使用<a href="https://developer.wordpress.org/reference/functions/get_search_form/" target="_blank" rel="noreferrer noopener" aria-label="(在新窗口打开)">get_search_form()</a>
  • 要包含自定义主题文件,请使用<a href="https://developer.wordpress.org/reference/functions/get_template_part/">get_template_part()</a>

评论 (0)

验证码
评论需要审核后才会显示

暂无评论,快来抢沙发吧!

文章信息

分类 技术
发布时间 2025年12月03日
作者 管振佐
浏览量 140 次