移植其他 WordPress theme 的思路
  1. 不采用商业的可拖放式的 theme,意义不大,采用传统的 theme 即可。
  2. 安装一个 Show Current Template 插件,用来在 Admin 的工具栏上展示当前页面采用的页面模版,方便定位页面路径。
  3. 在搞站点之前先搞点临时数据,临时数据直接让 chatgpt 来生成 plugin,激活插件初始化假数据。
  4. 有些外部链接图片,需要拷贝其他网站的页面 html,通过正则表达式过滤出来,这里使用的 editplus 过滤器脚本的方式。
  5. 直接在 https://codesandbox.io/ 设计一个 tailwind 样式的网页,然后拿过来套。
  6. https://github.com/solstice23/argon-theme 使用的传统方式模版,响应速度还不够快,参看一下转为 tailwind 方式模板。

Editplus 过滤器脚本

Dim stdin, stdout, input

Set stdin = WScript.StdIn
Set stdout = WScript.StdOut
input = stdin.ReadAll()

' 创建正则表达式对象
Set objRegExp = CreateObject("VBScript.RegExp")
objRegExp.IgnoreCase = True  ' 忽略大小写
objRegExp.Global = True  ' 匹配所有结果

' 设置正则表达式模式
objRegExp.Pattern = "data-src=""(.*?)"""  ' 匹配 data-src 属性中的内容

' 使用正则表达式查找匹配的内容
Set objMatches = objRegExp.Execute(input)

' 输出匹配的结果
For Each objMatch In objMatches
    stdout.WriteLine(objMatch.SubMatches(0))  ' 输出捕获组中的内容
Next

生成假数据的 plugin

<?php
/*
Plugin Name: Retro Games Post Generator
Plugin URI: https://yourwebsite.com/plugin-005
Description: 插入50条关于复古游戏的随机帖子到数据库,并在插件初始化时清空所有数据,同时为每篇帖子生成特色图片并插入文章内容
Version: 1.0
Author: Your Name
Author URI: https://yourwebsite.com
License: GPL2
Text Domain: plugin-005
*/

// 清除所有相关数据表内容的函数
function clear_all_data_on_plugin_activation() {
    global $wpdb;

    // 清空 wp_posts 表中的所有数据
    $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}posts");

    // 清空 wp_terms 表中的所有数据
    $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}terms");

    // 清空 wp_term_taxonomy 表中的所有数据
    $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}term_taxonomy");

    // 清空 wp_term_relationships 表中的所有数据
    $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}term_relationships");

    // 清空 wp_postmeta 表中的所有数据
    $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}postmeta");

    // 清空 wp_termmeta 表中的所有数据
    $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}termmeta");

    // 输出清除完成的信息
    echo "All relevant data has been cleared!";
}

// 获取随机的复古游戏封面图
function get_random_featured_image() {
    $image_urls = [
        'https://i.987967.xyz/previews/spyu.png',
        'https://i.987967.xyz/previews/spy.png',
        'https://i.987967.xyz/previews/srdmissn.png',
        'https://i.987967.xyz/previews/ssmissin.png',
        'https://i.987967.xyz/screenshot/19/s/svgpcb.png',
        'https://i.987967.xyz/screenshot/19/s/svg.png',
        'https://i.987967.xyz/previews/sabotenb.png',
        'https://i.987967.xyz/previews/sabotenba.png',
        'https://i.987967.xyz/screenshot/19/s/sadari.png',
        'https://i.987967.xyz/screenshot/19/s/safarirj.png',
        'https://i.987967.xyz/screenshot/19/s/safarir.png',
        'https://i.987967.xyz/screenshot/19/s/saiyugoub1.png',
        'https://i.987967.xyz/screenshot/19/s/saiyugoub2.png',
        'https://i.987967.xyz/screenshot/19/s/saiyugou.png',
        'https://i.987967.xyz/previews/nspiritj.png',
        'https://i.987967.xyz/screenshot/19/s/stdragonb.png',
        'https://i.987967.xyz/screenshot/19/s/stdragon.png',
        'https://i.987967.xyz/screenshot/19/s/stdragona.png',
        'https://i.987967.xyz/screenshot/19/s/salamand.png',
        'https://i.987967.xyz/screenshot/19/s/salamandj.png',
        'https://i.987967.xyz/screenshot/19/2022/09/02/43397_19a21ad196eb57a739431a472f96c484593ada39.png',
        'https://i.987967.xyz/previews/samesame.png',
        'https://i.987967.xyz/previews/samesame2.png',
        'https://i.987967.xyz/screenshot/19/2018/01/18/34274_ab3f8dc4aa9aa65ecd07617aa3f6df0fda313b2f.png',
        'https://i.987967.xyz/previews/samuraia.png',
        'https://i.987967.xyz/screenshot/19/t/tsamuraih.png',
        'https://i.987967.xyz/screenshot/19/t/tsamurai.png',
        'https://i.987967.xyz/screenshot/19/t/tsamurai2.png',
        'https://i.987967.xyz/previews/samshoh.png',
        'https://i.987967.xyz/screenshot/19/2018/01/26/34278_205a48aea6fa13269c13c3a0399c21dc49d3d0e1.png',
        'https://i.987967.xyz/previews/samsho.png',
        'https://i.987967.xyz/previews/samsho2.png',
        'https://i.987967.xyz/screenshot/19/2018/01/28/34279_e48c27bea1f8b9da2926c45c0021514134e2ac98.png',
        'https://i.987967.xyz/previews/samsho3h.png',
        'https://i.987967.xyz/previews/samsho3.png',
        'https://i.987967.xyz/previews/samsho4.png',
        'https://i.987967.xyz/screenshot/19/2018/01/26/34280_f2a1453374a8aac10e80348a58d9897788bf3a99.png',
        'https://i.987967.xyz/previews/samsho5b.png',
        'https://i.987967.xyz/screenshot/19/2018/01/30/34281_d8dcca04fc832520b05674dd15384f9419d700b9.png',
        'https://i.987967.xyz/previews/samsho5h.png',
        'https://i.987967.xyz/previews/samsho5.png',
        'https://i.987967.xyz/previews/samsh5spho.png',
        'https://i.987967.xyz/previews/samsh5sph.png',
        'https://i.987967.xyz/previews/samsh5sp.png',
        'https://i.987967.xyz/screenshot/19/s/sandscrp.png',
        'https://i.987967.xyz/screenshot/19/s/sandscrpb.png',
        'https://i.987967.xyz/screenshot/19/s/sandscrpa.png',
        'https://i.987967.xyz/previews/wofa.png',
        'https://i.987967.xyz/previews/wofah.png',
        'https://i.987967.xyz/previews/wofaha.png',
    ];

    // 随机选择一张图片
    return $image_urls[array_rand($image_urls)];
}

// 插入帖子到数据库的函数
function insert_retro_games_posts() {
    global $wpdb;

    // 预定义的一些复古游戏和相关元素
    $retro_games = [
        "Super Mario Bros.", "Pac-Man", "Space Invaders", "Donkey Kong", "Galaga", 
        "The Legend of Zelda", "Tetris", "Street Fighter II", "Sonic the Hedgehog", 
        "Metroid", "Castlevania", "Asteroids", "Pong", "Final Fantasy", "Mega Man",
        "Duck Hunt", "Contra", "Excitebike", "Dig Dug", "Frogger"
    ];

    $categories = ["Retro Games", "Classic Gaming", "Arcade Legends", "Old School Games", "Vintage Consoles"];
    $tags = ["1980s", "90s Gaming", "Classic", "Arcade", "Old School", "Pixel Art", "Retro Gaming", "Console History", "Nostalgia"];

    // 清除数据
    clear_all_data_on_plugin_activation();

    // 确保所有分类都存在,并设置 slug
    foreach ($categories as $category) {
        if (!term_exists($category, 'category')) {
            wp_insert_term($category, 'category', [
                'slug' => sanitize_title($category)  // 为分类设置slug
            ]);
        }
    }

    // 插入50条帖子
    for ($i = 0; $i < 50; $i++) {
        $title = "Exploring " . $retro_games[array_rand($retro_games)] . ": A Retro Gaming Classic";
        $content = "Join us as we dive into the nostalgic world of " . $retro_games[array_rand($retro_games)] . "! This game, a classic from the golden age of arcades, takes players on an unforgettable adventure filled with exciting challenges and iconic gameplay mechanics. From its pixel-perfect graphics to its timeless music, " . $retro_games[array_rand($retro_games)] . " continues to capture the hearts of gamers around the world.";

        // 生成帖子 slug
        $post_slug = sanitize_title($title);  // 使用帖子标题生成 slug

        $category = $categories[array_rand($categories)];
        $post_tags = implode(", ", array_rand(array_flip($tags), 3));  // 随机选择3个标签

        // 获取分类的ID
        $category_id = get_cat_ID($category);

        // 获取随机的外部特色图片 URL
        $featured_image_url = get_random_featured_image();

        // 插入到wp_posts表中
        $post_data = [
            'post_title'   => $title,
            'post_content' => '<img src="' . $featured_image_url . '" alt="' . $title . '" />' . $content, // 在文章内容前插入图片
            'post_status'  => 'publish',  // 设置为已发布状态
            'post_author'  => 1,  // 默认作者ID
            'post_date'    => current_time('mysql'),
            'post_date_gmt' => current_time('mysql', 1),
            'post_name'    => $post_slug  // 设置帖子 slug
        ];

        // 使用wpdb进行插入
        $wpdb->insert($wpdb->prefix . 'posts', $post_data);

        // 获取新插入帖子ID
        $post_id = $wpdb->insert_id;

        // 关联分类
        wp_set_post_categories($post_id, [$category_id]);

        // 给帖子添加标签
        wp_set_post_tags($post_id, $post_tags);

        // 设置外部特色图片
        set_post_thumbnail($post_id, thumbnail_id: $featured_image_url);  // 直接使用URL设置特色图片

        // 插入5条评论
        for ($j = 0; $j < 5; $j++) {
            $comment_content = "This is a comment on the post about " . $retro_games[array_rand($retro_games)] . ".";
            $comment_data = [
                'comment_post_ID' => $post_id,
                'comment_content' => $comment_content,
                'user_id'         => 1,  // 默认评论者ID
                'comment_date'    => current_time('mysql'),
                'comment_approved' => 1
            ];

            // 如果是第二条或更多评论,则将其设置为回复某条评论
            if ($j > 0) {
                $comment_data['comment_parent'] = $wpdb->get_var("SELECT comment_ID FROM {$wpdb->prefix}comments WHERE comment_post_ID = $post_id LIMIT 1 OFFSET " . ($j - 1));
            }

            // 插入评论
            wp_insert_comment($comment_data);
        }
    }

    echo "50 posts have been successfully inserted with featured images, images in content, and comments!";
}

// 激活插件时清除数据并插入数据
register_activation_hook(__FILE__, 'insert_retro_games_posts');
?>
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇