WordPress 开发教程路线图
13 2025-07-11
下面是去掉了 “1. 安装开发环境” 后、重新编号的 WordPress 开发教程路线图。其他内容保持不变,方便你直接复制粘贴使用。
核心目录
wp-content/
– 主题和插件所在目录
wp-admin/
– 后台管理界面
wp-includes/
– 核心功能文件
一个主题至少需要两个文件:
style.css # 主题元信息 + 样式index.php # 默认模板
theme-name/├── style.css├── functions.php├── index.php├── header.php├── footer.php├── sidebar.php├── page.php├── single.php└── screenshot.png
常用函数:
get_header()
, get_footer()
the_title()
, the_content()
have_posts()
, the_post()
, get_template_part()
用于注册:
菜单:register_nav_menus()
小工具:register_sidebar()
主题支持:add_theme_support('post-thumbnails')
等
<?php/*Plugin Name: My Custom PluginDescription: 插件描述Version: 1.0Author: 你的名字*/
动作钩子(Action):add_action('init', 'my_function')
过滤器钩子(Filter):add_filter('the_content', 'my_filter')
使用 $wpdb
类操作数据库:
global $wpdb;$wpdb->insert($wpdb->prefix . 'my_table', ['name' => 'Jack']);
添加后台菜单:add_menu_page()
添加设置页面:add_options_page()
使用 Settings API 保存配置
register_post_type('portfolio', [ 'label' => '作品集', 'public' => true, 'supports' => ['title', 'editor', 'thumbnail'],]);
使用 Advanced Custom Fields (ACF) 插件
或者手写 meta box
(add_meta_box()
)
WP 默认接口:/wp-json/wp/v2/posts
自定义接口:register_rest_route()
缓存插件:WP Super Cache、W3 Total Cache
使用 CDN
精简主题结构与查询
限制后台登录尝试
不暴露 WordPress 版本
定期备份数据库与文件
如果还需要删除、增补或深入某一部分,随时告诉我!