Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 像WordPress那样访问样式表注释_Php_Css_Wordpress - Fatal编程技术网

Php 像WordPress那样访问样式表注释

Php 像WordPress那样访问样式表注释,php,css,wordpress,Php,Css,Wordpress,我想知道如何使用PHP访问样式表顶部的注释,就像WordPress那样 如果我们为WordPress创建一个新主题,那么我们必须在样式表中的“注释”下输入我们的名称、博客名称和一些其他参数。WordPress访问这些评论并将它们显示为您的主题信息 那么有人知道怎么做吗?答案是找到WordPress用来做这件事的代码 我在完整的WordPress代码库中快速搜索了“style.css”,并在upgrade.php第1764行中找到了一个函数,名为function make_site_theme_f

我想知道如何使用PHP访问样式表顶部的注释,就像WordPress那样

如果我们为WordPress创建一个新主题,那么我们必须在样式表中的“注释”下输入我们的名称、博客名称和一些其他参数。WordPress访问这些评论并将它们显示为您的主题信息


那么有人知道怎么做吗?

答案是找到WordPress用来做这件事的代码

我在完整的WordPress代码库中快速搜索了“style.css”,并在upgrade.php第1764行中找到了一个函数,名为function make_site_theme_from_default($theme_name,$template),似乎就是这样做的

函数使用此代码执行以下操作:

// Rewrite the theme header.
$stylelines = explode("\n", implode('', file("$site_dir/style.css")));
if ($stylelines) {
    $f = fopen("$site_dir/style.css", 'w');

    foreach ($stylelines as $line) {
        if (strpos($line, 'Theme Name:') !== false) $line = 'Theme Name: ' . $theme_name;
        elseif (strpos($line, 'Theme URI:') !== false) $line = 'Theme URI: ' . __get_option('url');
        elseif (strpos($line, 'Description:') !== false) $line = 'Description: Your theme.';
        elseif (strpos($line, 'Version:') !== false) $line = 'Version: 1';
        elseif (strpos($line, 'Author:') !== false) $line = 'Author: You';
        fwrite($f, $line . "\n");
    }
    fclose($f);
}

通常,他们/你会将文件作为文本读取,然后解析注释。这并不难,但也不是小事。请参阅。@Shaun:阅读此副本。