方法一:
html页面名称为example
- 将 example.html 修改为 page-example.php 上传到当前使用的主题目录中;
- 在WordPress后台创建别名为 example 的页面,发布。
注:创建的页面别名一定要与page-后面一样。或者在步骤1中将页面名称example改为页面ID。
方法二:
- 将 example.html 修改为page-template-example.php 然后再该文件头部添加:
<?php
/*
Template Name: example 页面模板
*/
?>
`
上传page-template-example.php到当前使用的主题目录中;
- 在WordPress后台创建别名为 example 的页面并选择页面模板为第一步中创建的example页面模板,然后发布。
如果添加的页面是首页,可以在 设置 > 阅读 > 首页显示 中设置将此页面设置为首页。
关于CSS、JS、图片等外部文件引用
如果页面有引用CSS、JS以及图片,例如:sample.css、sample.js、sample.jpg,可以将这些文件一并复制到主题目录下,然后引用地址改为:
<link href="<?php echo get_theme_file_uri( 'sample.css' ); ?>" rel="stylesheet" type="text/css" />
<script src="<?php echo get_theme_file_uri( 'sample.js' ); ?>" type="text/javascript"></script>
<img src="<?php echo get_theme_file_uri( 'sample.jpg' ); ?>" />
注:引用文件应该加上详细地址路径