Jump to content

Echo Image in Wordpress Post


melting_dog

Recommended Posts

Hi guys -  a bit of a wierd one - I have installed a plugin that allows me to run PHP from a WP post or page - but I am having difficulty (probably with the syntax) when echoing an image. I know I must use the bloginfo("template_directory") but I am not sure how to include it in an echo - especially drawing the image path form a DB row..

 

eg:

 

echo '<img src="' . bloginfo("template_directory") . $row['itemimage'] . '"/>';

 

In this form, the template directory path is simple printed to the screen as a string - the image itself fails to appear. I simply cannot get this to work.

 

Can any one help me out? Sorry if this is unclear.

 

Thanks heaps again!

Link to comment
Share on other sites

I have no way of knowing what bloginfo("template_directory") will translate to. So let's use images as the place where my images are stored.

To echo  out a stored image using

$row["itemimage"] = '1.jpg';

I'd use this code:

echo "<img src=\"images/".$row['itemimage']."\" />";

 

So substituting the bloginfo("template_directory") gives:

echo "<img src=\"bloginfo(\"template_directory\")".$row['itemimage']."\" />";

 

If that does not work you may need to add a / to bloginfo(\"template_directory\") as I have done with images.

 

 

A good way to check what you have is to write a php script with

echo "<img src=\"bloginfo(\"template_directory\")".$row['itemimage']."\" />";

As the only line.

Then open it in your browser and view the page source to see what is missing.

 

Link to comment
Share on other sites

  • 2 weeks later...

Allright - un update on this, sorry for the delay - was away overseas.

 

I decided to just past the entire first part of the path in to see what happens:

 

echo '<img src="http://localhost/xampp/website/uploads/'. $row['itemimage'] . '"/>';

 

Still got no image, so I opened up firebug. I see the complete image path in the code there that should be working, but with a little message saying it failed to load the image.

 

I copied the entire path into my browser and got a 403 error:

 

Access forbidden!

 

New XAMPP security concept:

 

Access to the requested object is only available from the local network.

 

This setting can be configured in the file "httpd-xampp.conf".

 

 

Is this something to do with XAMPP? I tried googling it and couldnt find anything to that helped. Can someone point me in the right direction?

 

Thanks!

 

 

Link to comment
Share on other sites

Have you tried looking in the httpd-xampp.conf file? Xampp sux balls because it teaches people to be lazy and not bother actually learning how things work / should be configured. Apache HTTP is the server underneath.

 

Anyway, there is likely an access restriction preventing access from outside of the local network. Still though, localhost can actually only ever resolve to the local machine so....

 

Still, this might be of some use: http://httpd.apache.org/docs/2.0/mod/mod_access.html#allow

Link to comment
Share on other sites

Hi Thorpe

 

- yes I have looked at the xxamp file. I googled a fix on the 403 error and most sites recommend I change the line 'Allow from localhost' to 'Allow from 127.0.0.1'

 

I tried to find the line but my file has this instead:

 

<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">

    Order deny,allow

    Deny from all

    Allow from ::1 127.0.0.0/8 \

              fc00::/7 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 \

              fe80::/10 169.254.0.0/16

 

    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var

</LocationMatch>

 

Would you know how I could modify this to help?

 

Cheers

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.