Initial WordPress theme

This commit is contained in:
2026-06-25 15:57:22 +08:00
commit 043faa8b98
19 changed files with 1161 additions and 0 deletions

105
setup-demo.php Normal file
View File

@@ -0,0 +1,105 @@
<?php
define('WP_USE_THEMES', false);
require '/var/www/html/wp-load.php';
$site_url = getenv('GX_SITE_URL') ?: 'http://81.70.133.57:8080';
function gx_ensure_page($title, $slug, $template = '') {
$page = get_page_by_path($slug, OBJECT, 'page');
$data = array('post_title' => $title, 'post_name' => $slug, 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => '');
if ($page) { $data['ID'] = $page->ID; $id = wp_update_post($data); } else { $id = wp_insert_post($data); }
if (!is_wp_error($id) && $template) update_post_meta($id, '_wp_page_template', $template);
return is_wp_error($id) ? 0 : $id;
}
function gx_ensure_cat($name, $slug) { $term = get_category_by_slug($slug); if ($term) return $term->term_id; $created = wp_insert_term($name, 'category', array('slug' => $slug)); return is_wp_error($created) ? 1 : intval($created['term_id']); }
function gx_upsert_post($data, $cat_id) {
$existing = get_page_by_path($data['slug'], OBJECT, 'post');
$post = array('post_title'=>$data['title'],'post_name'=>$data['slug'],'post_content'=>$data['content'],'post_excerpt'=>$data['excerpt'],'post_type'=>'post','post_status'=>'publish','post_date'=>$data['date'].' 09:00:00','post_category'=>array($cat_id),'tags_input'=>$data['tags']);
if ($existing) { $post['ID'] = $existing->ID; $id = wp_update_post($post); } else { $id = wp_insert_post($post); }
if (!is_wp_error($id)) update_post_meta($id, '_gx_view_count', intval($data['views']));
return $id;
}
function gx_ensure_menu_location($location, $menu_name) {
$locations = get_theme_mod('nav_menu_locations', array());
$menu = wp_get_nav_menu_object($menu_name);
if (!$menu) {
$menu_id = wp_create_nav_menu($menu_name);
$menu = wp_get_nav_menu_object($menu_id);
}
if ($menu && !empty($menu->term_id)) {
$locations[$location] = (int) $menu->term_id;
set_theme_mod('nav_menu_locations', $locations);
}
return $menu && !empty($menu->term_id) ? (int) $menu->term_id : 0;
}
switch_theme('gongxue-from-zero');
wp_delete_post(1, true);
$hello = get_page_by_title('Hello world!', OBJECT, 'post');
if ($hello) {
wp_delete_post($hello->ID, true);
}
$home_id = gx_ensure_page('首页', 'home', 'front-page.php');
$knowledge_id = gx_ensure_page('知识库', 'knowledge');
gx_ensure_page('刷题题库', 'question-bank', 'page-question-bank.php');
gx_ensure_page('在线网校', 'online-school', 'page-online-school.php');
gx_ensure_page('出版书籍', 'books', 'page-books.php');
update_option('show_on_front', 'page');
update_option('page_on_front', $home_id);
update_option('page_for_posts', $knowledge_id);
update_option('home', $site_url);
update_option('siteurl', $site_url);
update_option('blogname', '恭学教育');
update_option('blogdescription', '天津专升本智慧教育平台');
update_option('posts_per_page', 10);
update_option('default_category', 1);
update_option('blog_public', 1);
update_option('timezone_string', 'Asia/Shanghai');
$cats = array('考试政策'=>'exam-policy','院校专业'=>'school-intro','专业指南'=>'major-guide','复习规划'=>'study-method','学长经验'=>'experience');
$cat_ids = array(); foreach ($cats as $name => $slug) $cat_ids[$name] = gx_ensure_cat($name, $slug);
$posts = array(
array('title'=>'2026年天津高职升本科考试报名热点问答发布','slug'=>'2026-tianjin-zhuanshengben-registration-faq','content'=>'<p>天津市教育招生考试院近日发布了2026年天津市高职升本科招生工作安排。</p><h2>一、报名条件</h2><p>符合下列条件的人员,具备报名资格。</p>','excerpt'=>'最新报名政策详解。','category'=>'考试政策','tags'=>array('置顶','官方','必读'),'date'=>'2026-01-15','views'=>23800,'sticky'=>true),
array('title'=>'天津专升本2026年院校专业选择攻略','slug'=>'2026-tianjin-school-major-guide','content'=>'<p>天津专升本招生院校众多,专业选择复杂。</p>','excerpt'=>'全面梳理天津各大本科院校专升本招生专业。','category'=>'院校专业','tags'=>array('干货','必读'),'date'=>'2026-01-08','views'=>12700),
array('title'=>'高数复习黄金期,如何利用刷题题库高效提分?','slug'=>'advanced-math-question-bank-study-plan','content'=>'<p>专升本高数考试临近,如何高效利用刷题题库提升成绩?</p>','excerpt'=>'冲刺阶段的高数复习策略。','category'=>'复习规划','tags'=>array('干货','热门'),'date'=>'2026-01-05','views'=>8300),
array('title'=>'专升本英语核心词汇如何分阶段记忆','slug'=>'english-vocabulary-stage-memory','content'=>'<p>英语词汇复习不是简单重复背诵。</p>','excerpt'=>'把高频词、真题语境和错题复盘结合起来。','category'=>'专业指南','tags'=>array('英语','方法'),'date'=>'2025-12-28','views'=>4600),
array('title'=>'从专科到本科学姐的380天复习心路历程','slug'=>'student-success-380-days','content'=>'<p>我是天津某专科院校2025届毕业生。</p>','excerpt'=>'380天备考之路。','category'=>'学长经验','tags'=>array('经验','热门'),'date'=>'2025-12-20','views'=>11200),
);
$sticky = array();
foreach ($posts as $p) { $id = gx_upsert_post($p, $cat_ids[$p['category']] ?? 1); if (!empty($p['sticky'])) $sticky[] = $id; }
update_option('sticky_posts', $sticky);
update_option('seo_title', '恭学教育 - 天津专升本培训领军品牌 | 刷题题库 | 在线网校 | 出版书籍');
update_option('seo_description', '恭学教育专注天津专升本 7 年,提供刷题题库、在线网校、出版书籍和知识库文章,帮助学员高效升本。');
update_option('seo_keywords', '天津专升本,恭学教育,刷题题库,在线网校,出版书籍,知识库');
if ($home_id && $knowledge_id) {
$menu_id = gx_ensure_menu_location('primary', '主导航菜单');
if ($menu_id) {
$existing_items = wp_get_nav_menu_items($menu_id, array('post_status' => 'publish'));
$existing_titles = array();
foreach ($existing_items as $menu_item) {
$existing_titles[] = trim($menu_item->title);
}
$items = array(
array('title' => '首页', 'object_id' => $home_id, 'object' => 'page', 'type' => 'post_type', 'url' => get_permalink($home_id)),
array('title' => '刷题题库', 'object_id' => (get_page_by_path('question-bank', OBJECT, 'page') ? get_page_by_path('question-bank', OBJECT, 'page')->ID : 0), 'object' => 'page', 'type' => 'post_type', 'url' => home_url('/question-bank/')),
array('title' => '在线网校', 'object_id' => (get_page_by_path('online-school', OBJECT, 'page') ? get_page_by_path('online-school', OBJECT, 'page')->ID : 0), 'object' => 'page', 'type' => 'post_type', 'url' => home_url('/online-school/')),
array('title' => '出版书籍', 'object_id' => (get_page_by_path('books', OBJECT, 'page') ? get_page_by_path('books', OBJECT, 'page')->ID : 0), 'object' => 'page', 'type' => 'post_type', 'url' => home_url('/books/')),
array('title' => '知识库', 'object_id' => $knowledge_id, 'object' => 'page', 'type' => 'post_type', 'url' => get_permalink($knowledge_id)),
);
foreach ($items as $item) {
if (!in_array($item['title'], $existing_titles, true) && !empty($item['object_id'])) {
wp_update_nav_menu_item($menu_id, 0, array(
'menu-item-title' => $item['title'],
'menu-item-object-id' => $item['object_id'],
'menu-item-object' => $item['object'],
'menu-item-type' => $item['type'],
'menu-item-status' => 'publish',
'menu-item-url' => $item['url'],
));
}
}
}
}
update_option('permalink_structure', '/%postname%/');
flush_rewrite_rules();
echo "ok\n";