close
lost pwd
view the inbox only after signing in or commenting
fold toggle
stickers by Twitter
sticker
Muyue

第一步、先配置个脚本,生成css静态文件:update-css.sh...
#!/bin/bash
# /usr/local/bin/update-css.sh

THEME_DIR="/www/wwwroot/博客文件夹/wp-content/themes/pink"
CSS_DIR="$THEME_DIR/css"
DOMAIN="https://你的网址"

cd "$CSS_DIR"

# 检查PHP文件是否有更新
for php_file in *.css.php; do
if [ -f "$php_file" ]; then
css_file="${php_file%.php}"

# 如果PHP文件比CSS文件新,则重新生成
if [ "$php_file" -nt "$css_file" ] || [ ! -f "$css_file" ]; then
echo "Updating $css_file..."
curl -s "$DOMAIN/wp-content/themes/pink/css/$php_file" > "$css_file"

# 检查文件是否成功生成
if [ -s "$css_file" ]; then
echo "Successfully generated $css_file ($(stat -c%s "$css_file") bytes)"
# 设置正确的权限
chmod 644 "$css_file"
else
echo "Failed to generate $css_file"
fi
fi
fi
done

echo "CSS files updated successfully!"


第二步、在 `header.php` 中修改 fun_themefile_include 函数第18行,添加静态CSS文件检测逻辑:
if ($suffix == 'css') {
// 检查静态CSS文件是否存在
$static_file = get_template_directory() . '/' . $path . trim($file) . '.css';
if (file_exists($static_file)) {
// 使用静态CSS文件
$file_completion = $path . trim($file) . '.css';
} else {
// 使用PHP生成的CSS文件
$file_completion = $path . trim($file) . '.css.php';
}
} else {
$file_completion = $path . trim($file) . '.' . $suffix;
}


第三步、伪静态增加缓存时间(可选)
# 静态CSS文件缓存配置
location ~* \.css$ {
expires 30d;
add_header Cache-Control "public, max-age=2592000";
add_header Vary Accept-Encoding;
}

# JavaScript文件缓存配置
location ~* \.js$ {
expires 30d;
add_header Cache-Control "public, max-age=2592000";
add_header Vary Accept-Encoding;
}

# 您的原有配置
location / {
try_files $uri $uri/ /index.php?$args;
}

rewrite /wp-admin$ $scheme://$host$uri/ permanent;


第四步、设置脚本自动更新:
0 2 */7 * * /www/wwwroot/你的存放文件夹/wp-content/themes/pink/css/update-css.sh

show moreshow less

interact
Comment
Muyue

😘 回来了 PINK

interact
Comment
Muyue

快乐小窝😎

interact
Comment
Muyue


欢迎使用 WordPress。这是您的第一篇文章。编辑或删除它,然后开始写作吧!


interact
Comment
close
darkmode toggle
i like it
totop
Designed by Kam
粤ICP备2022125592号-1
loading...
Previous Next EscClose +SDownload