如果你想为你的WordPress网站创建自定义页面模板,可以按照以下步骤:
创建一个新的PHP文件,并在文件的开头使用注释来指定模板名称和描述。例如:
/*
* Template Name: Custom Page Template
* Description: A custom page template for my site.
*/
编写PHP代码来定义你的页面模板,并将代码保存到新创建的PHP文件中。例如,以下代码将创建一个具有自定义标题的页面模板:
<?php
/*
* Template Name: Custom Page Template
* Description: A custom page template for my site.
*/
get_header();
?>
<h1>This is my custom page!</h1>
<?php
get_footer();
?>
将文件保存到你的WordPress网站的主题文件夹中,例如“wp-content/themes/mytheme/”。
在创建或编辑页面时,可以从页面属性下拉菜单中选择你的自定义页面模板。选择后,WordPress将使用你创建的模板来呈现页面。
示例代码:
<?php
/*
* Template Name: Custom Page Template
* Description: A custom page template for my site.
*/
get_header();
?>
<h1>This is my custom page!</h1>
<?php
get_footer();
?>