Image Not Loading (WordPress Template) - php

Im adding an image to my wordpress theme through dreamweaver cs4 and themedreamer. The image will go in the sidebar.php. When I inserted an image it doesnt shows in firefox and explorer. With safari, the image only shows an empty box with a question sign in the middle.
Is there a special way to add image in a wordpress template?

Prepend below line to images's src:
<?php echo get_bloginfo('template_url'); ?>
Making your src something like this:
<img src="<?php echo get_bloginfo('template_url'); ?>/images/yourimage.gif" alt="" />

No, but you have to get the value of the src attribute correct.

Related

How to get image url of img tag in wordpress

I'm creating a wordpress theme. and i want some of the images to remain static. how can i get the url behind my image source.
My Default Image URL
<img src="assets/logo/logo.jpg">
I was trying <img src="../assets/logo/logo.jpg">
Is there any function of wordpress that we can use to get the url of an image?
You need to get the full path of the theme folder too you can do it like this
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/logo/logo.jpg">

Displaying image from different disk

Hi i want to show images from different disk.
Here is my code.
is it possible to do that ?
$a = "D:/img/1.jpg";
<img src="<?php echo $a; ?>" alt="...">
Im using this on my localhost.This is not for the web.
i add screenshot here.
when i come above the img it shows the link. but not show img. and i use lightbox.
but without lightbox its not show again.
example
The sample you provided/attached is only doable if you load the html file directly to your browser. It is not possible if you load it via localhost. In your case, you will have to do something like this:
<?php
$image = file_get_contents('D:/img/1.jpg');
$image_codes = base64_encode($image);
?>
<image src="data:image/jpg;charset=utf-8;base64,<?php echo $image_codes; ?>" />
Reference: How to retrieve and show images from another drive using src attribute in <img> tag?
I'd suppose to use such URLs with protocol: $a = 'file:///D:/img/1.jpg';

Image is not displaying in Yii

I have img tag in my view file (yii frame work). and image is displayed in most of the times. some times the images are not displaying. when I inspect the element, then it shows the img path as src="hhhh://localhost/projects/aaa/images/sample-img-left.png". here for http://, hhhh:// comes. Iam not getting any idea with how this hhhh comes. help me please
You can call Yii::app()->request->baseUrl to get the location where your project resides, then append it with the image path.
For Eg.
<img src="<?php echo Yii::app()->request->baseUrl."/images/sample-img-left.png" ?>" />

How to print Image gallery descriptions

I have a image gallery with 15 pics, it shows the first image in normal size and the rest are thumbs on the bottom, when you click the thumbs it replaces the normal size image with that one, and if you click the normal sized image it shows on a lightbox style popup with the image description.
This gallery layout is called Galleria and its part of the SIG Pro joomla plugin:
http://demo.joomlaworks.net/simple-image-gallery-pro
The image descriptions for each image are shown on the popup, but I would like to remove this behavior and show the description below the normal sized image.
My question is regarding PHP, I'm very noob at this.
For what I figured out I can print all the thumbs descriptions with this:
<?php foreach($gallery as $count=>$photo): ?>
<p class="sigProGalleriaTargetTxt"><?php echo $photo->captionDescription; ?></p>
<?php endforeach; ?>
But what I want to print is only the description of the image that is selected.
I tried this:
<p class="sigProGalleriaTargetTxt"><?php echo $gallery[0]->captionDescription; ?></p>
But this only prints the first image description, because it has the value 0 (first image).
I see that I need to increment the value of $gallery according to the selected image.
How can I achieve this?
Here is the complete php file:
http://codepad.org/MlPbgPzl
Thank you,
What about using som javascript/dom to set the captions? its a bit of a hacky but, i would try to have an onClick Event which calls a function to apply the description.
in the thumbs sections something like:
<span class="sigProLinkWrapper">
<a onClick="setDesc('<?php echo $photo->captionDescription; ?>');" href="...
and for the description:
// leaving the <?php tag like this, so you get always the first description
// but adding an id tag
<p id='photoDescription' class="sigProGalleriaTargetTxt">$gallery[0]->captionDescription; ?></p>
and finally replacing it with some javascript (or jquery if youre using that)
function setDesc(photoDesc)
{
var descContainer = document.getElementById("photoDescription").innerHTML= photoDesc;
}
maybe it helps :)

How to add images to a wordpress theme when working on MAMP?

I am new to MAMP and I am developing a theme I designed. However I can't seem to get the images to render. I am using a clear theme I got from starkerstheme.com
When adding an image directly to the code I used:
<img src="<?= $theme ?>/images/logo.png"/>
But the image is not showing up, also I tried to add it to the media library and it's still not rendering.
This works for me:
<img src="<?php echo get_bloginfo('template_url') ?>/images/logo.png"/>
See get bloginfo() function for more info.
You can use the following code to add an image. This works for me:
<img src="<?php echo get_template_directory_uri(); ?>/images/filename.png">
<?php echo get_template_directory_uri(); ?>
as suggested gets the PARENT theme, which is OK but if you've developed a child theme (as recommended by WordPress people) you need:
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/Logo.png">
Just go to your dashboard and upload your picture in the media section, then select it you'll see the image options .. then copy it's url
<img src="your/copied/url"/>
This aslo works for me in localhost
You might need to do the full <img src="<?php echo $theme; ?>/images/logo.png"/>
Update I didn't read your question closely enough. If you're using the media library for the image, you'll need to specify the actual path to the image. You can figure this out from within the media library, but it's probably site_url/wp-content/uploads/2012/01/filename.jpg
In short, if you uploaded it in media, it wouldn't actually be in your theme.
<?php bloginfo('template_directory'); ?>/
use for internal root folder in images to place on theme on wordpress.
The forward slash is needed for the image to show
Remove the = after <?
<img src="<? $theme ?>/images/logo.png"/>
in fact, I'd probably do something like this:
<img src= <?php $theme ?> . "/images/logo.png"/>
on 2021...
Just name the image as screenshot.png [ recommended image size (currently) is 1200px wide by 900px ] and put it on theme's top-level directory (where the style.css file is )
and that's all you need to do.

Categories