【问题标题】:Wordpress Theming, Unable to locate stylesheets in scripts.phpWordpress 主题,无法在 scripts.php 中找到样式表
【发布时间】:2014-11-10 00:27:54
【问题描述】:

(我正在关注这本书“引导站点蓝图”,现在我在第 3 章。它介绍了使用 Roots 作为 Wordpress 的起始主题。) 我正在为 Wordpress 创建自定义主题,当我尝试通过修改 scripts.php 连接到自己的样式表时遇到问题。

这是我的文件结构:

|bootstrappin-theme
   |assets
       |css
           |main.css
   |lib
       |scripts.php

这是scripts.php中的相关代码

if (WP_ENV === 'development') {
   $assets = array(
      'css'       => '/assets/css/main.css',
      'js'        => '/assets/js/scripts.js',
      'modernizr' => '/assets/vendor/modernizr/modernizr.js',
      'jquery'    => '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js'
  );
} 
else {
    $get_assets = file_get_contents(get_template_directory() . '/assets/manifest.json');
    $assets     = json_decode($get_assets, true);
    $assets     = array(
      'css'       => '/assets/css/main.min.css?' . $assets['assets/css/main.min.css']['hash'],
      'js'        => '/assets/js/scripts.min.js?' . $assets['assets/js/scripts.min.js']['hash'],
      'modernizr' => '/assets/js/vendor/modernizr.min.js',
      'jquery'    => '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'
    );
}

wp_enqueue_style('roots_css', get_template_directory_uri() . $assets['css'], false, null);

然后我检查了浏览器,请求“main.css”时出现 404 错误,其中 url 从请求日志中读取:“127.0.0.1/wordpress/assets/css”


所以我将css 的路径从'/assets/css/main.css' 更改为

'/wp-content/themes/bootstrappin-theme/assets/css/main.css'.

现在看起来像:

if (WP_ENV === 'development') {
$assets = array(
  'css'       => '/wp-content/themes/bootstrappin-theme/assets/css/main.css',
...
wp_enqueue_style('roots_css', get_template_directory_uri() . $assets['css'], false, null);

但是,它仍然是 404 错误,奇怪的是,当我在浏览器中检查路径时,main.css 的路径仍然是

ma​​in.css

127.0.0.1/wordpress/assets/css

我发现的棘手部分是,路径输出永远不会到达我的bootstrappin-theme 文件夹及其

行为很奇怪。


示例 1

例如,如果我将scripts.php 中的代码更改为

/wp-content/themes/bootstrappin-theme-example/assets/css/main.css

浏览器中的路径输出将忽略/wp-content/themes/bootstrappin-theme-example之前的所有内容,如下所示:

127.0.0.1/wordpress/assets/css

是的,和以前一模一样。


示例 2

如果我将代码更改为

/wp-content/themes-example/bootstrappin-theme/assets/css/main.css

输出将是:

127.0.0.1/wordpress/wp-content/themes-example/bootstrappin-theme/assets/css/main.css


提前谢谢你。

【问题讨论】:

    标签: wordpress wordpress-theming


    【解决方案1】:

    已回复here

    为避免这种情况,请修改 /wp-content/themes/bootstrappin-theme/lib/config.php 只需将此行(通常是第 6 行)转为 cmets:

    // add_theme_support('rewrites');

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-27
      • 1970-01-01
      • 2016-07-14
      • 2014-04-14
      • 1970-01-01
      • 1970-01-01
      • 2013-11-13
      • 2011-10-21
      相关资源
      最近更新 更多