WordPress 101 主题开发教程: 01 – 从头开始创建一个主题

01 – 从头开始创建一个主题

引言: 终于有时间把以前的想要学(其实早就该学)的知识进行整理学习,不想花太多时间,但又不得花多的时间,废话少说加油吧!

Thanks! Alessandro Castellani !

视频学习参考:https://www.youtube.com/watch?v=oTRZYnYQlmo&list=PLriKzYyLb28nUFbe0Y9d-19uVkOnhYxFE&index=1

第一节内容:主要讲解了WordPress的目录结构,只需要关心wp-content目录即可

wp-content/themes 和 wp-content/plugins 分别对应着主题和插件

开发环境开启:

1. 开启开发环境:首先需要打开debug参数开关,在根目录的wp-config.php文件中 修改为

define(‘WP_DEBUG’, true);

然后进入主题文件夹 wp-content/themes 创建自己的主题目录 比如 z

2. 创建2个必要结构文件:

第1个重要的识别文件 style.css 内容要按照标准再顶部加入注释格式

/*
Theme Name: z
Theme URI: https://wordpress.org/themes/twentyseventeen/
Author: the WordPress team
Author URI: https://wordpress.org/
Description: Twenty Seventeen brings your site to life with header video and immersive featured images. With a focus on business sites, it features multiple sections on the front page as well as widgets, navigation and social menus, a logo, and more. Personalize its asymmetrical grid with a custom color scheme and showcase your multimedia content with post formats. Our default theme for 2017 works great in many languages, for any abilities, and on any device.
Version: 2.2
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: twentyseventeen
Tags: black, white, one-column, two-columns, right-sidebar, flexible-header, accessibility-ready, custom-colors, custom-header, custom-menu, custom-logo, editor-style, featured-images, footer-widgets, post-formats, rtl-language-support, sticky-post, theme-options, threaded-comments, translation-ready
*/

第2个重要的模板文件index.php

<?php get_header(); ?>
<h1>This is my index
<?php get_footer(); ?>

3. 创建模板头尾部文件header.php footer.php

Super easy! Super beginer beginer!

一个冷笑话

神父:你是否愿意爱他无论疾病还是健康?新娘:我愿意。神父:你是否愿意爱他直到死亡将你们分开?新娘:我愿意。神父:你是否愿意想吃薯条时自己另外点一份,而不是坚称自己不想要接着以尝一根为名吃掉他一半的薯条? 新娘:。。。这玩意谁写的?新郎:少废话,快说是!