wordpress主题开发1-主题模板文件结构

wordpress最让人心动的功能就是它的丰富的插件和主题机制,对于个人开发者来说,开发一款属于自己的主题和插件是每个人梦寐以求的,特别是对于那些审美有着严格最求的人,他们非常希望自己的网站有着自己想要的样式。

wordpress 主题开发可以说很简单,也可以说很复杂,简单的是它可以很快上手,复杂的是,你需要掌握很多技巧,才能开发出优雅的模板结构,才能适应各种环境。

wordpress的主题目录是在wp-content\themes目录下,你可以自己新建一个主题,然后创建一个style.css文件,wordrpess是根据这个文件的注释来识别主题的相关信息的。

/**
Theme Name: 寻找天国
Text Domain: 梦回故里
Version: 1.2
Requires at least: 4.7
Requires PHP: 7.0
Description: Our default theme for 2020 is designed to take full advantage of the flexibility of the block editor. Organizations and businesses have the ability to create dynamic landing pages with endless layouts using the group and column blocks. The centered content column and fine-tuned typography also makes it perfect for traditional blogs. Complete editor styles give you a good idea of what your content will look like, even before you publish. You can give your site a personal touch by changing the background colors and the accent color in the Customizer. The colors of all elements on your site are automatically calculated based on the colors you pick, ensuring a high, accessible color contrast for your visitors.
Tags: blog, one-column, custom-background, custom-colors, custom-logo, custom-menu, editor-style, featured-images, footer-widgets, full-width-template, rtl-language-support, sticky-post, theme-options, threaded-comments, translation-ready, block-styles, wide-blocks, accessibility-ready
Author: the WordPress team
Author URI: https://www.80shihua.com/
Theme URI: https://wordpress.org/themes/xunzhaotianguo/
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
**/

这个是标准的一个注释结构,其中Theme Name是主题名,Author是作者名字,Version是版本号,当你设置完这些,在后台主题设置里面,就可以看见自己的主题了。主题的预览图片需要你在自己的主题目录放置一个screenshot.png文件即可

index.php是最重要的主题文件,它是定义主题显示内容的。

header.php是头部文件,引入js,css。

footer.php是底部文件,用来引入版权,友链等信息。

sidebar.php是插件文件,用来显示后台添加的插件。

有了这4个基本文件,我们就可以定义我们自己的主题了。