在“CSS”中访问全局变量(style.php) [英] Accessing global variable in "CSS" (style.php)

查看:248
本文介绍了在“CSS”中访问全局变量(style.php)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 <?php header(Content-type:text / css); ?> 

等等。



如何从style.php文件中访问全局变量或将变量传递给它?



我试图获得的代码在CSS中工作就像

  $ maincolor = $ cap-> br_main_color; 

另外:


  • 忽略缓存问题。这只是一个个人项目。

  • 将链接中的变量传递给样式表过于复杂(在我看来)。



编辑:作为一个更多的解释:我正在做的是产生一个基于多种颜色和计算阴影效果等阴影的整个主题。大约50%的风格有其中有一些PHP。一切正常,如果我手动输入颜色到style.php,但我试图使它变得更加简单,对于不太熟悉技术的人员和使用颜色选择器。

解决方案

要访问wordpress函数,您需要在style.php文件的顶部包含以下几行代码。

  define('WP_USE_THEMES',false); 
require('./ wp-blog-header.php');

第一行告诉wordpress不要运行与主题相关的过程,第二行运行wordpress引擎。在此之后,您可以访问wordpress函数和全局变量。


I'm doing a style.php CSS file so I can use some dynamic variables in the CSS within a Wordpress installation:

<?php header("Content-type: text/css"); ?>

and so on.

How can I access a global variable from within the style.php file or pass a variable to it?

The code I'm trying to get to work within the CSS is like

$maincolor = $cap->br_main_color;

Also:

  • Ignore the caching issue. This is just a personal project.
  • Passing the variable in the link to the stylesheet is too complex for this (in my opinion).

EDIT: As a bit more explanation: What I'm doing is generating an entire theme based of a number of colors and calculating shades for hover effects etc. Roughly 50% of the styles have some PHP within them. Everything works just fine if I manually input colors to style.php but I'm trying to make it even simpler for less tech-savvy people and use a color picker.

解决方案

To access the wordpress functions you need to include the following lines on top of your style.php file.

define('WP_USE_THEMES', false);
require('./wp-blog-header.php');

The first line tells wordpress not to run theme related processes and the second line runs the wordpress engine. After this point you have access to the wordpress functions and the global variables.

这篇关于在“CSS”中访问全局变量(style.php)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆