所以我试图寻找解决方案: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离线测试了我的代码,它运行正常吗?
EDIT 我在主题所在的主题中添加了一个图像文件夹 .
5 回答
在wp-content之上添加主页URL
尝试使用
get_template_directory()
功能<img class="nightsky" src="<?php echo get_stylesheet_directory_uri()?>/hrtbrk.png" alt="">
请尝试以下选项 .
尝试使用
get_stylesheet_directory_uri()
功能参考link
所以我想出了一个有效的方法,但这并不是我想要的方法 .
我需要直接通过wordpress媒体上传图片 .
哪个存储在
/wp-content/uploads
中我想让图像在主题文件夹wp-content/themes/fearnothing/images
内但由于某些奇怪的原因,文件被破坏了 . (因此破碎的图像文件)
在直接上传到uploads文件夹后,我能够使用我原来的标签 .