【发布时间】:2019-05-11 06:27:53
【问题描述】:
所以我试图寻找解决方案: custom wordpress theme: layout images not displaying
它对我不起作用。
我的主题目录是
wp-content/themes/fearnothing/
由这些文件组成
/css(folder)
/js (folder)
/images (folder)
header.php
index.php
function.php
footer.php
style.css
hrtbrk.gif
hrtbrk.png
css文件夹包含
fearnothing.css
js 文件夹为空
fearnothing.js
我的 header.php 有以下代码:
<!DOCTYPE html>
<html>
<head>
<title>example title</title>
<?php wp_head(); ?>
</head>
<body>
<img class ="nightsky" src="wp-content/themes/fearnothing/hrtbrk.png" alt ="3">
functions.php
<?php
function fearnothing_script_enqueue(){
wp_enqueue_style('customstyle', get_template_directory_uri().'/css/fearnothing.css',array(), '1.1.2', 'all');
}
add_action('wp_enqueue_scripts', 'fearnothing_script_enqueue');
fearnothing.css
html,body{
background: black;
color: #8c0707;
font-family: Courier,Courier New,Lucida Sans Typewriter,Lucida Typewriter,monospace;
font-size: 10px;
cursor: pointer;
}
.nightsky{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 500px;
height: 500px;
}
我正在尝试添加 gif,但它不起作用。所以我尝试了一张图片。我用 html 离线测试了我的代码,它工作正常吗?
编辑 我在主题所在的主题中添加了一个图像文件夹。
【问题讨论】:
-
header.php 中的标记错误。将图片标签改为:
<img class ="nightsky" src="wp-content/themes/fearnothing/hrtbrk.png" alt=""> -
在你的所有文件中也没有“hrtbrk.png”
-
啊,应该更正一下。他们在那里,我只是在这里打错了。我做了你建议的改变,但没有奏效:/
-
您是否尝试过直接打开图像文件? yourdomain.com/wp-content/themes/fearnothing/hrtbrk.png
-
@peter-cs 这(“不只是把我带到我的网站”)是问题所在。它与 wordpress 或您的 HTML 无关。您的服务器配置似乎是错误的。如果您尝试打开图像并被重定向到网站,则找不到该图像或服务器不允许访问此文件。正如您所解释的,这也可以解释为什么它在使用 wordpress 媒体上传时起作用。这是另一个目录。