甚至不确定方法是否是正确的术语......
这是原始的工作代码:
<a href="<?php bloginfo('url'); ?>">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/logo.png" alt="Polished Logo" id="logo"/></a>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/separator.png" width="2" height="59" alt="Line" class="logo_line"/>
<p id="logo_title"><?php bloginfo('description'); ?></p>
Run Code Online (Sandbox Code Playgroud)
我希望它只在主页上执行,所以我写了这个:
<?
if ( $_SERVER["REQUEST_URI"] == '/' ){
echo '<a href="'.bloginfo('url').'">
<img src="'.bloginfo('stylesheet_directory').'/images/logo.png" alt="Polished Logo" id="logo"/></a>
<img src="'.bloginfo('stylesheet_directory').'/images/separator.png" width="2" height="59" alt="Line" class="logo_line"/>
<p id="logo_title">'.bloginfo('description').'</p>';
}
?>
Run Code Online (Sandbox Code Playgroud)
但是它bloginfo()完全在我创建的html标签之外输出和其他声明.例如,bloginfo('stylesheet_directory')它将显示IMG我创建的标签之外的目录.
有任何想法吗?显然我的语法不正确或者......
Nit*_*dra 11
bloginfo函数直接回显输出.在这种情况下,您应该使用get_bloginfo将返回的值添加到字符串并回显完整的字符串.我相信这会奏效
<?php
if ( $_SERVER["REQUEST_URI"] == '/' ) {
echo '<a href="'.get_bloginfo('url').'">
<img src="'.get_bloginfo('stylesheet_directory').'/images/logo.png" alt="Polished Logo" id="logo"/></a>
<img src="'.get_bloginfo('stylesheet_directory').'/images/separator.png" width="2" height="59" alt="Line" class="logo_line"/>
<p id="logo_title">'.get_bloginfo('description').'</p>';
}
?>
Run Code Online (Sandbox Code Playgroud)
这是一个更好的选择:
<?php if ( $_SERVER["REQUEST_URI"] == '/' ) { ?>
<a href="<?php bloginfo('url') ?>">
<img src="<?php bloginfo('stylesheet_directory') ?>/images/logo.png" alt="Polished Logo" id="logo"/>
</a>
<img src="<?php bloginfo('stylesheet_directory') ?>/images/separator.png" width="2" height="59" alt="Line" class="logo_line"/>
<p id="logo_title"><?php bloginfo('description') ?></p>
<?php } ?>
Run Code Online (Sandbox Code Playgroud)
我还建议使用is_home()wordpress提供的功能来检查主页,而不是检查$_SERVER['REQUEST_URI']值.
| 归档时间: |
|
| 查看次数: |
2377 次 |
| 最近记录: |