自定义wordpress主题:布局图像不显示

时间:2011-08-03 10:01:54

标签: php html css image wordpress

我正在构建一个自定义的wordpress主题。所以我的主题文件夹包含以下文件/文件夹:

header.php
index.php
footer.php
style.css
/images
 picture-1.jpg

我的问题是我无法在index.php,header.php和footer.php中使用 img TAG 正确显示图像:

[..]
<div class="module">
<h4>General info</h4>
<img src="images/picture-1.jpg"/>
[..]

enter image description here

图片已存在,并且如果由style.css引用正确显示:

.banner{
  background-image:url(images/picture-1.jpg);
}

我错过了什么吗?

感谢 卢卡

2 个答案:

答案 0 :(得分:12)

这是因为您的文件不在/images相对于您正在查看的页面,而是在wp-content/themes/[yourthemename]/images

您可以通过在网站的head部分设置网站根目录的base网址并按照上图所示链接图片或使用以下内容来解决此问题:

<img src="<?php bloginfo('template_directory'); ?>/images/picture-1.jpg" alt="alt text" />

答案 1 :(得分:0)

试试这个:

<img src="<?php echo get_template_directory_uri();?>/images/img-9.png"/>