WordPress 开源项目教程
1. 项目的目录结构及介绍
WordPress 项目的目录结构如下:
/wordpress/
├── wp-admin/
├── wp-content/
│ ├── plugins/
│ ├── themes/
│ └── uploads/
├── wp-includes/
├── wp-config-sample.php
├── index.php
├── license.txt
├── readme.html
├── wp-activate.php
├── wp-blog-header.php
├── wp-comments-post.php
├── wp-config-sample.php
├── wp-cron.php
├── wp-links-opml.php
├── wp-load.php
├── wp-login.php
├── wp-settings.php
├── wp-signup.php
├── wp-trackback.php
└── xmlrpc.php
目录介绍
wp-admin/
:包含 WordPress 管理后台的文件。wp-content/
:包含主题、插件和上传的文件。plugins/
:存放所有插件的目录。themes/
:存放所有主题的目录。uploads/
:存放上传文件的目录。
wp-includes/
:包含 WordPress 核心功能的文件。wp-config-sample.php
:配置文件的示例。index.php
:WordPress 的主入口文件。license.txt
:WordPress 的许可证文件。readme.html
:WordPress 的介绍文件。- 其他 PHP 文件是 WordPress 的核心功能文件。
2. 项目的启动文件介绍
WordPress 的启动文件主要是 index.php
,它是 WordPress 的主入口文件。当用户访问网站时,服务器会首先加载这个文件。
index.php 文件内容概述
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
这个文件主要做了以下几件事:
- 定义常量
WP_USE_THEMES
为true
,表示使用主题。 - 加载
wp-blog-header.php
文件,该文件负责加载 WordPress 环境和模板。
3. 项目的配置文件介绍
WordPress 的配置文件是 wp-config.php
,通常在安装过程中从 wp-config-sample.php
复制并修改而来。
wp-config.php 文件内容概述
<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the installation.
* You don't have to use the web site, you can copy this file to "wp-config.php"
* and fill in the values.
*
* This file contains the following configurations:
*
* * MySQL settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* @link https://wordpress.org/support/article/editing-wp-config-php/
*
* @package WordPress
*/
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
/**#@+
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {@link https://api.wordpress.