有没有办法混合使用CSS和PHP? [英] Is there a way to mix CSS and PHP?
问题描述
我正在研究wordpress主题,并且我希望有一个自定义标题背景.我曾经使用wordpress提供的 add_theme_support('custom-header);
函数,它可以工作,但不是我想要的.我想要背景图片而不是img.我创建了一个名为header_background_callout()的函数,并添加了一个部分,设置和控件.该功能起作用,并输出用户通过wordpress中的定制"部分选择的背景网址.有没有办法我可以在CSS中做类似的事情?: background-image:url(<?php echo wp_get_attachment_url(<?php get_theme_mod());?>);
I'm working on a wordpress theme, and i want to have a custom header background. I used to use add_theme_support('custom-header);
function that wordpress offers, it works but not the way i want it to. I want to have a background-image instead of an img. I made a function called header_background_callout() and i added a section, setting and control. the function works and outputs the background url that the user chooses through the customize section in wordpress. Is there a way that i can do something like this in css? : background-image: url(<?php echo wp_get_attachment_url(<?php get_theme_mod()); ?>);
谢谢.
推荐答案
是的.
我将css文件制成了php文件,因此,我可以按照您所说的做
Yes kind off.
I made my css file a php file and because of that I can do as you say
background-image: url(<?php echo get_theme_mod(); ?>); // I suppose you need to echo the mod?
在HTML中,您可以像这样使用它;
In the HTML you use it like;
<Link rel="stylesheet" type="text/css" href="style.php">
编辑,您可能需要通过以下方法将php文件的标头更改为css文件:
Edit you may need to change the header of the php file to a css file by:
<?php header("content-type: text/css; charset: UTF-8"); ?>
这篇关于有没有办法混合使用CSS和PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!