php - 通过 php 显示来自 css 的元素

标签 php css wordpress

我实际上正在制作一个皮肤菜单,例如输入/输出 => 在我的 wordpress 皮肤上显示皮肤选项,以便用户更容易使用它。但是,我一直试图让 Logo 显示出来,但一直失败……我已经将 CSS 与 PHP 合并,使其能够获取函数名称;但它不会在背景中显示图像。

这是 css/php 文件,名为 bg_image.php。

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

#logo_main{
    background:url('<?php echo get_settings('ld_header_img'); ?>') no-repeat;
}

通过将其包含到标题中:

<link rel="stylesheet" type="text/css" href="./bg_image.php" />

当然,还有 functions.php,它有数组等等,可以让这个东西工作......

$themename = "LightD";
$shortname = "ld";

$options = array (

array( "name" => $themename." Options",
    "type" => "title"),

array( "name" => "Homepage",
    "type" => "section"),
array( "type" => "open"),

array( "name" => "Homepage header image",
    "desc" => "Enter the link to an image used for the homepage header.",
    "id" => $shortname."_header_img",
    "type" => "text",
    "std" => ""),

array( "type" => "close"),
array( "name" => "Footer",
    "type" => "section"),
array( "type" => "open"),

array( "name" => "Footer copyright text",
    "desc" => "Enter text used in the right side of the footer. It can be HTML",
    "id" => $shortname."_footer_text",
    "type" => "text",
    "std" => ""),

array( "type" => "close")

);

注意 完整的 functions.php 源代码/示例可以在下面的链接中找到;我查看了这个主题以获取此信息: http://net.tutsplus.com/tutorials/wordpress/how-to-create-a-better-wordpress-options-panel/

地点:

name: The name of the input field.

desc: A short description explaining what it is to the user.

id: the id of the field, prefixed by the shortname. It will be used to store as well as access the options.

type: the input type – select, text or textarea

options: used to declare an array of options for a select type input.

std: the default input value, used if no other input is given.

这就是我的问题所在...我尝试在 中使用“style”,它奏效了:

<div id="logo_main" style="background:url('<?php echo get_settings('ld_header_img'); ?>') no-repeat;">
<div id="branding">
<div id="blog-title"><?php if ( is_singular() ) {} else {echo '<h1>';} ?><a href="<?php echo /*home_url()*/"./home/" ?>/" title="<?php bloginfo( 'name' ) ?>" rel="home"><?php bloginfo( 'name' ) ?></a><?php if ( is_singular() ) {} else {echo '</h1>';} ?></div>
<p id="blog-description"><?php bloginfo( 'description' ) ?></p>
</div>
</div>

我的问题是;为什么 CSSed PHP 不起作用?!

最佳答案

您的文件不知道使用过的函数。您需要添加 include 语句。

<?php 
error_reporting(E_STRICT); 
ini_set('display_errors', 1);
include('path-to/functions.php');
header("Content-type: text/css"); 
?>

#logo_main{
    background:url('<?php echo get_settings('ld_header_img'); ?>') no-repeat;
}

关于php - 通过 php 显示来自 css 的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10186041/

相关文章:

wordpress - Amazon S3 - 如何每月将 1 个备份文件转换到 Glacier

php - 在 pdo 循环时插入失败 (pdo/php 5.6)

php - 我无法从 Laravel 中的请求 AJAX 检索数据

php - 获取 Shopware 6 集合元素的值,PHP

html - 粘贴剪贴板 HTML 数据并保留 CSS 和图像

css - 使 Bootstrap 3 Carousel 成为文本滑过的单个静态图像

php - 如何根据 php 标题的长度调整 margin-top 属性?

php - 上传照片并将其名称添加到 MySQL

javascript - 如何在 Angular 服务中调用页面加载函数

css - 如何在手机和桌面上制作固定的整页背景图片? Wordpress - Divi - CSS