在php文件中使用bloginfo和div

时间:2016-10-14 作者:Gecko Boy

以下代码位于中。php文件和作品;然而,我不知道如何用bloginfo(\'template_directory\') 到内部图像文件。我已经在论坛上搜索过了,但我找不到一种方法来实现这一点。有没有更简单的方法?

if ( $colors && in_array(\'green\', $colors) ) {
    echo \'<div class="asdsf">\' . "TEXT" . \'</div>\';
}

1 个回复
SO网友:Andy Macaulay-Brook

我想你也想要一个图像标签:

if ( $colors && in_array( \'green\', $colors ) ) {
    echo \'<div class="asdsf"><img src="\';
    echo bloginfo(\'template_directory\') . \'/path/within/theme/to/img.png\';
    echo \'"></div>\';
}
但最好用新的get_stylesheet_directory_uri() 无论您是否使用子主题,它都会起作用。

if ( $colors && in_array( \'green\', $colors ) ) {
    echo \'<div class="asdsf"><img src="\';
    echo get_stylesheet_directory_uri() . \'/path/within/theme/to/img.png\';
    echo \'"></div>\';
}