WordPress.org

Ready to get started?Download WordPress

Forums

PHP not displaying images from database (16 posts)

  1. michaelsambol
    Member
    Posted 2 years ago #

    Hello, I am running a php plugin (http://wordpress.org/extend/plugins/allow-php-in-posts-and-pages/) and I am trying to post an image on a page. The image is in the following location: /wp-content/images/. However, the image will not display (instead it displays a broken image link). I have looked at several posts about this problem, but nothing seems to work. Any help is appreciated! Thanks! (code below)

    <img src="<?php bloginfo('template_directory'); ?>/wp-content/images/pic.jpg" />

  2. Threecows
    Member
    Posted 2 years ago #

  3. Threecows
    Member
    Posted 2 years ago #

    Try this:

    <?php echo '<img src="' . content_url() . '/images/pic.jpg' . '" />'; ?>
  4. Threecows
    Member
    Posted 2 years ago #

    Just wandering why you use bloginfo('template_directory')

    Anyhow use get_bloginfo('template_directory') in this case.

  5. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    @michaelsambol

    providing a link to the page displaying the problem, or copying the corresponding portion of output html would help tremendously for these types of questions.

    Being able to investigate the actual html helps pinpoint the problem

  6. michaelsambol
    Member
    Posted 2 years ago #

    @Threecows Adding "get_" in front of "bloginfo" worked! Thanks!

  7. michaelsambol
    Member
    Posted 2 years ago #

    Sorry, I have one follow-up. What should I do if the link to the image is dynamic, not static. Instead of /wp-content/images/pic.jpg, I need $picture

    I am trying to populate a table of images from a folder

  8. Threecows
    Member
    Posted 2 years ago #

    I rewrote this code assuming you have a folder named "/wp-content/images" in your template folder.

    $img_dir = TEMPLATEPATH . '/wp-content/images/' ;
    $files=glob($img_dir . '*.*');
    foreach ($files as $file) {
    	$fileinfo = getimagesize($file);
    	if ($fileinfo[0] > 0) { //it's an imagefile
    		$pathinfo = pathinfo($file);
      	 	echo '<img src="' . get_bloginfo('template_directory') . '/wp-content/images/' . $pathinfo['filename'] . '.' . $pathinfo['extension'] . '" />';
    	}
    }
  9. michaelsambol
    Member
    Posted 2 years ago #

    Nothing is printing :/

    I tried to simplify it and print just one image, but the image doesn't print. Here is the code I used:

    echo '<img src="' . get_bloginfo('template_directory') . '/wp-content/images/pic.jpg' . '" />';

  10. Threecows
    Member
    Posted 2 years ago #

    What is the full path of the folder containing the images ??

    Check things out to construct the correct URI's :

    echo ABSPATH . "<br />";
    echo content_url() . "<br />";
    echo TEMPLATEPATH . "<br />";
    echo get_bloginfo('template_directory');
  11. Threecows
    Member
    Posted 2 years ago #

    I installed the plugin you use for displaying php.
    Put the code in a post and it is indeed not printing anything.
    Look's like the plugin won't handle complicated strings.

  12. Threecows
    Member
    Posted 2 years ago #

    I suggest you'd better make a custom plugin instead of using this 'php show plugin' for this purpose.

    Here's the code for the test-plugin:
    http://pastebin.com/WEiQJqfr

    Just copy the code into a new textfile and name it testplugin.php
    Upload the file to your plugin directory.
    Activate it.
    Add the shortcode [test] to a post.

  13. michaelsambol
    Member
    Posted 2 years ago #

    YES THANK YOU Threecows. It works. You're amazing. Appreciate the help.

  14. michaelsambol
    Member
    Posted 2 years ago #

    @Threecows haha now the test plugin seems to be interfering with the theme ... for example, the theme's shortcode for button ( [button] ) no longer produces a button..

  15. Threecows
    Member
    Posted 2 years ago #

    Strange...
    The only thing I can think of is the shortcode and the name "test" is not unique enough.

    Try this:
    In testplugin.php find and replace ALL words matching "test" with "myown".
    (this will change the plugin name and function names as well which is no problem at all)

    Upload end replace testplugin.php
    Use the shortcode [myown] in the post.

  16. Threecows
    Member
    Posted 2 years ago #

    Aha :)
    The button will probably show up, but you won't see it in the mess of images displayed in the post...
    You'll have to edit the testplugin and add br tags for instance.
    You can best edit the function "my_test_replstring"

Topic Closed

This topic has been closed to new replies.

About this Topic