I have a site done in PHP using SMarty templates (that I didn't create). The following code is used in the view_video.tpl to generate a button with a function attached to the onclick action.
<div class="user-button" id="user-button-up">
<a href="javascript:void();" onclick="video_description_toggle()">
<img height="16" width="16" src="images/user-arrow.jpg">
</a>
</div>
<div class="user-button" id="user-button-down" style="display:none;">
<a href="javascript:void();" onclick="video_description_toggle()">
<img height="16" width="16" src="images/user-arrow-down.jpg">
</a>
</div>
I noticed these buttons were not showing up on the page, so I ran the page through Pingdom (tools.pingdom.com) which breaks down each element of a page and how long it took to load etc. On the page results, the two images (user-arrow.jpg and user-arrow-down.jpg) show a file path of: sitename.com/video/41137/images/
None of the other images have this incorrect file path, just these two.
When I view the source of the page from a browser it shows:
<div class="user-button" id="user-button-up">
<a href="javascript:void();" onclick="video_description_toggle()">
<img height="16" width="16" src="images/user-arrow.jpg">
</a>
</div>
<div class="user-button" id="user-button-down" style="display:none;">
<a href="javascript:void();" onclick="video_description_toggle()">
<img height="16" width="16" src="images/user-arrow-down.jpg">
</a>
</div>
In the video/ directory there are only videos, no folders with numbers (or with image directories in them)... I'm sure this should be easy for anyone with PHP experience using templates (that's just not me... yet).
Thank you.
The path in img is relative to the url shown, not where the template is stored, so if you're in sitename.com/video/41137/ it will look for the images folder here, unless you add a slash or "../../" before "images"
Related
Alright, I have a file named slider.php which contains a bootstrap slider and I'm inserting pictures inside the slider but I can't figure out the correct way of writing the path to the pictures
<div class="carousel-inner">
<div class="item active">
<img class="slide-image" src="" alt="">
</div>
<div class="item">
<img class="slide-image" src="" alt="">
</div>
<div class="item">
<img class="slide-image" src="" alt="">
</div>
The slider.php is in this location ecomcopy/resources/front/slider.php
and the pictures are in ecomcopy/resources/img/
I tried everything and I can't get the correct pictures path
Can someone help?
The way paths work is to go "up" to parent folders until you're at a common ancestor. Then go back down naming folders until you get to the file you're referencing.
ecomcopy/resources/front/slider.php
ecomcopy/resources/front/ (start)
ecomcopy/resources/ (up 1) ../
ecomcopy/resources/templates/ (down to folder) templates/
ecomcopy/resources/templates/img/ (down to folder) img/
ecomcopy/resources/templates/img/yourimage.png
(down to file) yourimage.png
result: ../templates/img/yourimage.png
should be ../../img/image_name.png
It would be much easier (at least on a live server setting) to just specify absolute paths for your URLs.
For example, the following HTML is all that is needed to serve your images:
<img src="/ecomcopy/resources/templates/img/yourimage.png" />
There is no real need to worry about complicated relative file paths.
I have the following html code that tried to place in my WordPress page.
html:
<div class="hovereffect">
<img src="<?php echo get_template_directory_uri() ?>phone.jpg" >
<div class="overlay">
<h2>Hover effect 9</h2>
<a class="info" href="#">link here</a>
</div>
</div>
At the moment everything is in the site except the image that does not show.
How can I use this code WordPress in a way that it can display the image?
I think you forget to tell which place it should get the images from. And you are also forgetting a semicolon after the get_template_directory_uri();.
This is an example, but here i'm telling which folder to get the image from:
<img src="<?php echo get_template_directory_uri(); ?>/assets/images/your_image.jpg">
you can do that but it is not a good practice to paste this code as it is in WordPress editor,
upload this image in media and get link of that image
Edit page, select text mode from top right corner of your editor and paste code these i.e
<div class="hovereffect">
<img src="http://example.com/wp-content/uploads/2016/07/img.png" >
<div class="overlay">
<h2>Hover effect 9</h2>
<a class="info" href="#">link here</a>
</div>
</div>
Here is good practice create a template for that page and write there your code.
Image replace with feature image
Heading with page title.
Detail with page content
link with page permalink.
Not enough reputation to leave a comment so I will leave this as an answer instead.
Assuming phone.jpg is at the root of your theme, you're forgetting the / (slash) before phone.jpg.
It should be
<img src="<?php echo get_template_directory_uri(); ?>/phone.jpg" >
PHP won't get parsed inside a page. Just upload the image to the WordPress media library and link to it directly.
I started to learn Wordpress and I'm making my own theme. Within the design I have some images that are supposed to show up... but they don't.
I was using this code:
<div class="col-xs-4">
<img src="images/html_brand.jpg" class="img-responsive">
</div>
and then I found I should use php to link to my image:
<div class="col-xs-4">
<a href="#">
<img src="<?php bloginfo('stylesheet_directory'); ?>html_brand.jpg"
class="img-responsive">
</a>
</div>
But the problem is, the image still doesn't get displayed. And yes I did upload them to my web server. I have them in the directory of my theme: mythemename/images/html_brand.jpg
If you use bloginfo() to output your theme path, you need to add another /, followed by the remaining path to your image. Based on where you've placed your image, this should work:
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/html_brand.jpg" class="img-responsive">
However, bloginfo() ultimately relies on get_template_directory_uri() to work, so you might as well just use that:
<img src="<?php echo get_template_directory_uri(); ?>/images/html_brand.jpg" class="img-responsive">
Slight Correction:
bloginfo() with the specific argument of stylesheet_directory actually relies on get_stylesheet_directory_uri() to function -- get_template_directory_uri() like I originally said.
https://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/general-template.php#L439
I am calling socialmedia.php from every page on my website to display a little "Social Media" div where people can visit my social media pages.
I am calling this using <?php include './socialmedia.php' ?> or <?php include './socialmedia.php' ?> depending on what directory I am in.
In my socialmedia.php file I have the following code.
<a href="http://twitter.com/kinghenryharris" target="_blank">
<img class="socialMedia" src="../images/twitter_logo.png" alt="Twitter" width="40px" height="40px"></br>
</a>
<a href="http://facebook.com/kinghenryharris" target="_blank">
<img class="socialMedia" src="../images/facebook_logo.png" alt="Facebook" width="40px" height="40px"></br>
</a>
<a href="http://youtube.com/mrgorillalogic" target="_blank">
<img class="socialMedia" src="../images/youtube_logo.png" alt="Youtube" width="40px" height="40px"></br>
</a>
Is it bad practice if I am in the home directory to do ../images/youtube_logo.png
When calling it from www.example.com/page.php does it matter that I am going up two directories with ../images/youtube_logo.png`
It seems to work but I am wondering if this is wrong or I should change it so if I am in the home directory do ./images/youtube_logo.png or should I just leave it the same?
-Henry
I have been seriously been looking at this forever! I'm going out of my mind And can't figure out why my images are not displaying in my custom made footer.
I have firefox with firebug and it is simply saying that the url is failing to load. so I copy and pasted a url to an image that is currently working and is being shown via the background property in CSS just fine. (thats the top one that says dakota jones). copy and pasting the exact img src proves it still not to work.
my folder is images. My functions.php is right outside. the hierarchy is correct. what the heck?? The testing text in the p tags work just fine. uhuhuhu
Somebody help me! I'm using wp and genesis theme.
add_action('genesis_before_footer', 'include_sponsors');
function include_sponsors() { ?>
<div class="sponsors">
<p>This is testing text</p>
<img src="images/dakotajonesheader3.jpg" alt="Smiley face" height="42" width="42" />
<img src="images/tfobw.png" />
<img src="images/basskingbw.png" />
<img src="images/bighawgbw.png" />
<img src="images/kbw.png" />
<img src="images/mccoybw.png" />
<img src="images/nfcbwpng" />
<img src="images/rayjusbw.png" />
<img src="images/rrbw.png" />
</div>
<?php }
Use WordPress' inbuilt function:
<?php
bloginfo('template_directory'); ?>/images/dakotajonesheader3.jpg
?>
.. which will reference /wp-content/themes/your-theme/images/dakotajonesheader3.jpg
Wordpress dynamically rewrites URLs, so the URL you use to access a page is not the same as the path to the scripts that are running on the server. So you might request your page with example.com/Home. But your images are not stored in example.com/Home/images, which is where you're telling your browser to look. They're stored in example.com/wordpress/wp-content/themes/your_theme/images. So you have to give the absolute path to the images to the browser in your <img> tags.
Carson is correct, and you can use absolute paths to your images. Alternatively, if you want to avoid using absolute paths, you can call your images using bloginfo('template_directory');
For example:
<img src="<?php bloginfo('template_directory'); ?>/images/dakotajonesheader3.jpg" alt="Smiley face" height="42" width="42" />