Wordpress function.php 文件中的 PHP 条件语句不起作用
我想在 function.php
中执行以下 PHP 语句:如果有上传的 #header h1 a
背景图像,请缩进文本(删除)...如果不是(否则),请保留文本(不要缩进)。
我对 PHP 不太熟悉,但这就是我所做的:
<?php
// Include functions of Theme Options
require_once(TEMPLATEPATH . '/functions/admin-menu.php');
// If there's an image for the site title, remove it's text
function logo_exists() {
?><style type="text/css">
#header h1 a {
<?php
if ( $options['logo'] == NULL ) { ?>
float: left;
text-indent: 0;
<?php } else { ?>
background: url(<?php echo $options['logo']; ?>) no-repeat scroll 0 0;
float: left;
text-indent: -9999px;
width: 160px;
height: 80px;
}
<?php } ?>
</style><?php
}
header.php:
// Initiate Theme Options
$options = get_option('plugin_options');
var_dump($options['logo'])
?>
<style>
body {
background-color: <?php echo $options['color_scheme']; ?>
}
</style>
</head>
<body <?php body_class(); ?>>
<div id="wrapper">
<div id="header">
<h1>
<a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
</h1>
(我不确定它是否是有用的信息,但 plugin_options 是在
我做了 var_dump
和 #options['logo']
显示:(
string(63) "http://localhost/wordpress/wp-content/uploads/2010/12/logo3.png"
所以图像正在工作)
但现在我只看到 WordPress site title
我是否必须“激活”或“启动”功能 **logo_exists? 还是还有其他问题?**
(如果我不使用 PHP If 语句并直接从 header.php 声明 $options[logo] ,一切正常)
提前致谢!
I want to do the following PHP statement within function.php
: If there's an uploaded image for #header h1 a
's background, indent the text (remove)...If not (else), keep the text (don't indent it).
I'm not very familiar with PHP but this is what I did:
<?php
// Include functions of Theme Options
require_once(TEMPLATEPATH . '/functions/admin-menu.php');
// If there's an image for the site title, remove it's text
function logo_exists() {
?><style type="text/css">
#header h1 a {
<?php
if ( $options['logo'] == NULL ) { ?>
float: left;
text-indent: 0;
<?php } else { ?>
background: url(<?php echo $options['logo']; ?>) no-repeat scroll 0 0;
float: left;
text-indent: -9999px;
width: 160px;
height: 80px;
}
<?php } ?>
</style><?php
}
header.php:
// Initiate Theme Options
$options = get_option('plugin_options');
var_dump($options['logo'])
?>
<style>
body {
background-color: <?php echo $options['color_scheme']; ?>
}
</style>
</head>
<body <?php body_class(); ?>>
<div id="wrapper">
<div id="header">
<h1>
<a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
</h1>
(I'm not sure if it is useful information but plugin_options is initialised just before the <style>
tags.)
I did var_dump
and #options['logo']
displays:
string(63) "http://localhost/wordpress/wp-content/uploads/2010/12/logo3.png"
(So the image is working)
But right now I just see the Wordpress site title
Do I have to "activate" or "initiate" the function **logo_exists?
or is there another problem?**
(Everything works ok if I don't use the PHP If statements and declaring $options[logo] directly from header.php)
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$options
不存在于该函数的范围内。您需要在函数声明之后添加,以便它从包含中获取
$options
变量。像这样:$options
doesn't exist in the scope of that function. You need to addjust after the function declaration, so that it picks up the
$options
variable from the include. Like this: