Image not loading even though path is correct - php

The file path is:
theme
assets
src
images
grey-arrow.svg
Markup:
<?php $getIcon = get_template_directory().'/assets/src/images/grey-arrow.svg';?>
<div><img src="<?php echo $getIcon; ?>"/></div>
<?php echo $getIcon;?>
The image doesn't load and an echo of $getIcon returns:
/var/www/html/wp-content/themes/theme/assets/src/images/grey-arrow.svg
... Which is the correct path. Ideas on why the image doesn't load?

You should echo it and also you are closing your php tag properly.
<img src="<?php echo get_template_directory_uri(); ?>/assets/src/images/grey-arrow.svg"/>
or you can use bloginfo which is easier to remember and use (You need not echo)
<img src="<?php bloginfo('template_url'); ?>/assets/src/images/grey-arrow.svg"/>

Related

Linking in wordpress, which link is right?

Which link version is right - if any?
contact-us
contact-us
and image links:
<img alt="xxx" src="<?php echo get_home_url(null, 'fl-images/banner/teaser.png', null); ?>">
<img alt="xxx" src="<?php echo get_home_url(); ?>/fl-images/banner/svatebni-teaser.png">
For <a> tag use.
kontakty
For <img> tag use.
<img alt="xxx" src="<?php echo home_url('/fl-images/banner/svatebni-teaser.png'); ?>">
In your case both will work assuming fl-images is in the public root.
However, if you want to reference a blog id or add a scheme to the home URL context then you can use the arguments. eg: get_home_url( 2, 'contact-us/', 'https');.
See docs here

Display image from mysql in HTML

I am trying to display an image, whose path is stored in the DB. Although the file path is retrieved correctly the image is not displayed on the web page. This is the HTML snippet:
<img src="<?php echo $row["path"];
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
error_log($row['path'], 0);
error_log($row["path"], 0);
?>"/>
The output from above indicates that the file path is correct
[17-Jul-2016 10:44:22] ./uploads/18-araya.jpg
I initially tried the following but it didn't work either
<img src="<?=$row['path']?>"/>
simply use <img src="<?php echo $row['path'];?>"/>
If your image is not loaded, view the source code and check the src value.
You should use
<img src="<?= $row['path'];?>"/>
Change <img src="<?=$row['path']?>"/>
To
<img src="<?= echo $row['path']; ?>"/>

How to have image src a variable?

I want to keep src attribute in a variable. I am working on php and tried the following method but it doesn't display the image on html page.
Code:
<?php $path="C:/horizontal.jpg"; ?>
<image src="<?php echo $path; ?>" style="width:304px;height:228px" />
I think you can use this technique:
<?php $path="http://" . $_SERVER["SERVER_NAME"];?>
<img src="<?php echo $path.'/projectName/image.jpg'; ?>" style="width:304px;height:228px" />
Where:
$_SERVER["SERVER_NAME"]: to get the server name, for example: www.example.com.
Also you can use $_SERVER["SERVER_ADDR"], in this case you can get the address IP of your server, for example: "127.0.0.1".
I hope this information helps you.
Good Luck.
<?php $path="localhost/projectName/";?>
<img src="<?php echo $path.'image.jpg'; ?>" style="width:304px;height:228px" />

How to link thumbnail image to a large image

I'm trying to create a simple image gallery that displays thumbnails of uploaded images. Once a thumbnail is clicked, I would like to be directed to a page with the large version of the image, along with a comment section. So basically I'm trying to do something similar to deviantart. What I have now looks something like this:
<a href="<?php echo $image->large_image_path; ?>">
<img src="<?php echo $image->thumbnail_image_path; ?>"></a>
Clicking on a thumbnail will take to me to the large image path, which is not really what I want. Any help is greatly appreciated.
You must make the href="<?php echo $image->large_image_path; ?>" to somehing like href="show_image.php?image_path=<?php echo $image->large_image_path; ?>"
In show_image.php you can den get the path of the image by $_REQUEST['image_path'], and add it into the code like this:
<img src="<?php echo $_REQUEST['image_path']; ?> />
The you can add information or styling around the bigger image.
So, link to a PHP page instead of the image. Even better, put the image path in to a database, and use the image id to get the path and information of the image. Like this:
href="show_image.php?image_id=<?php echo $image->id; ?>"> and then in show_image.php, given that you have a method for getting the image:
<?php $image = GetImage($_REQUEST['image_id']); ?>
<img src="<?php echo $image->large_image_path; ?> />
<?php echo $image->description; ?>
<?php echo $image->date; ?>
Hope this helps you on the way.

PHP echo function inside a HTML link

I have a PHP echo function inside of a HTML link, but it isn't working. I want to have an image location, defined in img src, be in part of the clickable link of the image. The page will have multiple images doing the same thing, so I am trying to use PHP to automate this.
<a href="http://statuspics.likeoverload.com/<?php echo $image; ?>">
<img src="<?php $image=troll/GrannyTroll.jpg?>" width="100" height="94" />
</a>
Turn
<?php $image=troll/GrannyTroll.jpg?>
into
<?php echo "troll/GrannyTroll.jpg"; ?>
?
Or provide more details on what you are trying to achieve.
Also, you might consider urlencode-ing some of those URL parameters.
Edit:
So you might try setting the variable beforehand:
<?php $image = "troll/GrannyTroll.jpg"; ?>
<img src="<?php echo $picture; ?>" width="100" height="94" />
So now i understand what you are trying to do.
One error is that you didn't enclose $image=troll/GrannyTroll.jpg with quotes like this:
$image = 'troll/GrannyTroll.jpg';
The second error is that you do it in the wrong order, you have to define $image first, before you use it.
That's what I believe you want to do:
<?php
$image = "troll/GrannyTroll.jpg";
?>
<img src="<?php echo $image; ?>" width="100" height="94"/>

Categories