Html 本地计算机上的 Img Src
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15102122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Img Src on local computer
提问by Gregory Tippett
I imagine that this is a common beginner question, but I've found no responses that quite cover my problem: I am having trouble linking to an image on my local computer.
我想这是一个常见的初学者问题,但我没有找到完全涵盖我的问题的答案:我无法链接到本地计算机上的图像。
I'm working on making a theme for a wordpress installation (on a Dell running Windows 7 using Xampp.) My index.php
file is located at:
我正在为 wordpress 安装制作主题(在使用 Xampp 运行 Windows 7 的戴尔上)。我的index.php
文件位于:
C:\xampp\htdocs\tutorials\wordpress\wp-content\themes\LeftColumn\index.php
and the image I want to show is at:
我想展示的图像是:
C:\xampp\htdocs\tutorials\wordpress\wp-content\themes\LeftColumn\images\pmsplogo.jpg
... and while I've tried many variations, somehow nothing I put in the <img src=""/>
seems to be working. Can anyone explain what the right way to code this is for my situation?
...虽然我尝试了很多变化,但不知何故,我放入的任何东西<img src=""/>
似乎都不起作用。谁能解释一下针对我的情况进行编码的正确方法是什么?
Just to note, it will properly display an image from an external website (such as: http://littlewebhut.com/images/eightball.gif)
请注意,它将正确显示来自外部网站的图像(例如:http: //littlewebhut.com/images/eightball.gif)
Thanks!
谢谢!
回答by KatieK
Generally IE is OK with a path like C:\
, but other browsers need something more. Start the path with file:///C:/
and then fill in the rest of the path to the file through Windows Explorer.
通常 IE 可以使用类似 的路径C:\
,但其他浏览器需要更多。以 开始路径,file:///C:/
然后通过 Windows 资源管理器填写文件路径的其余部分。
But it might be best to consider relative paths - ../../images/src="img.gif"
- for example. This would be two directories up from the current location, and then into the images directory.
但最好考虑相对路径 -../../images/src="img.gif"
例如。这将是从当前位置向上的两个目录,然后进入图像目录。
回答by R T
You should add <?php bloginfo('template_url');?>
in front of the actual path. Let's suppose that you have a logo.png
image in a folder called images
in your theme. To link it in a Wordpress theme (index.php or other wordpress template pages) you do something like this:
您应该<?php bloginfo('template_url');?>
在实际路径前面添加。假设您在主题中logo.png
调用的文件夹中有一个图像images
。要将其链接到 Wordpress 主题(index.php 或其他 wordpress 模板页面)中,您可以执行以下操作:
<img src="<?php bloginfo('template_url');?>/images/logo.png" alt="Logo"/>
The above php function (bloginfo
) is calling for your template url. To this template url you need to add where the file actual file is in your theme (in this case /images/logo.png
).
上面的 php 函数 ( bloginfo
) 正在调用您的模板 url。在此模板 url 中,您需要添加文件实际文件在主题中的位置(在本例中为/images/logo.png
)。
Hopefully this makes sense.
希望这是有道理的。
回答by John Conde
Paths to files in HTML are from the web root. So \tutorials\wordpress\wp-content\themes\LeftColumn\images\pmsplogo.jpg
is the same on your local computer and remote server. If it isn't working then you need to make sure your paths are correct and you have set up both servers correctly.
HTML 文件的路径来自 Web 根目录。因此,\tutorials\wordpress\wp-content\themes\LeftColumn\images\pmsplogo.jpg
在本地计算机和远程服务器上的相同。如果它不起作用,那么您需要确保您的路径正确并且您已正确设置了两个服务器。
回答by Stepo
It is not necessaryto write whole pathin frame of template. This should suffice: \images\pmsplogo.jpg
这是没有必要的,以写完整的路径模板的框架。这应该足够了:\images\pmsplogo.jpg
Here's screen of my WordPress template, It's working very fine with entry described above:
这是我的 WordPress 模板的屏幕,上面描述的条目工作得很好:
If you were moving the template, you wouldn't need to change path of each img. It's big advantage.
如果您正在移动模板,则无需更改每个 img 的路径。这是很大的优势。