问题
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:
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?
Just to note, it will properly display an image from an external website (such as: http://littlewebhut.com/images/eightball.gif)
Thanks!
回答1:
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.
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.
回答2:
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:
<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 ).
Hopefully this makes sense.
回答3:
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.
回答4:
It is not necessary to write whole path in frame of template. This should suffice: \images\pmsplogo.jpg
Here's screen of my WordPress template, It's working very fine with entry described above:
- http://stepolabs.com/upload/path.png
If you were moving the template, you wouldn't need to change path of each img. It's big advantage.
来源:https://stackoverflow.com/questions/15102122/img-src-on-local-computer