【发布时间】:2015-03-14 15:52:40
【问题描述】:
我有一个小问题,我不确定如何解决,因为我在 php 中解析 css 文件有点天真。我正在使用 wordpress,并且正在构建一个功能,我需要动态地将宽度应用于我的元素。
理论上,在程序意义上,我的方法应该有效。
我所做的是在头文件中:
global$imageSlider;//global as needed in other files
$imageSlider=new slider();//my class
$imageSlider->add_css();//just an enqueue really.
//wp_enqueue_styles('image_slider_styles',get_template_directory_uri()."/css/imageSlider.css");
现在看到我的imageSlider.css 继续我的全局声明,我想该文件将能够使用$imageSlider。
使用 .htaccess 在 PHP 中解析 CSS 文件
<FilesMatch "\.(css)$">
AddHandler application/x-httpd-php .css
</FilesMatch>
这适用于局部变量。在我声明$imageSlider 之前是否正在解析这个文件?
在 CSS 文件中
header("Content-type: text/css; charset: UTF-8");
$pref=$imageSlider->build_css_widths();
//$imageSlider::build_css_widths() returns an array
//The rest of my styles
#imageSlider #sliderHolder{width:<?echo$pref['total'];?>%;}
class slider() 位于我的函数文件中。
有没有其他方法或者我错过了什么? 但它什么也没返回。 :(
我得到的错误是call to member function on non object,这基本上意味着从未声明过$imageSlider?
【问题讨论】: