基本步骤如下:
style.css
的样式表文件。示例代码:
/*
Theme Name: My Theme
Theme URI: http://example.com/my-theme
Author: John Doe
Author URI: http://example.com
Description: A description of my theme
Version: 1.0
License: GPL v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: responsive layout, custom header, custom background, threaded comments, translation-ready
*/
index.php
或 template.php
),并添加必要的 PHP 代码。示例代码:
<?php
/**
* Theme Name: My Theme
* ...
*/
// Add custom functions here
// Load the header template
get_header();
// Load the content template
get_template_part( 'content' );
// Load the sidebar template
get_sidebar();
// Load the footer template
get_footer();
?>
header.php
的文件,其中包含网站的头部内容。示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title><?php wp_title(); ?></title>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<header class="site-header">
<!-- Header content goes here -->
</header>
content.php
的文件,其中包含网站的主体内容。示例代码:
<div id="content" class="site-content">
<!-- Main content goes here -->
</div>
sidebar.php
的文件,其中包含网站的侧边栏内容。示例代码:
<aside class="site-sidebar">
<!-- Sidebar content goes here -->
</aside>
footer.php
的文件,其中包含网站的底部内容。示例代码:
<footer class="site-footer">
<!-- Footer content goes here -->
</footer>
<?php wp_footer(); ?>
</body>
</html>
在主题文件夹中创建一个新的文件夹(通常为 images
或 assets
),用于存储主题中使用的图像文件和其他资源文件。
根据需要,在主题文件夹中创建一个或多个附加模板文件(例如 page.php
、single.php
、archive.php
等),用于呈现特定类型的 WordPress 页面。
这些都是基本步骤。