• Hello,
    I’m having trouble linking to images using the img tag in a wordpress page. I need to do it this way so that the images can eventually be updated through the dashboard, using custom fields. Even though I’ve checked and rechecked the filepath (and know it to be correct as image shows when the page is previewed in dreamweaver), when the page is previewed in firefox or safari, I get a placeholder icon or alt text.

    When I make a graphic a background image of a div it shows up fine. Here is the code for my page, containing the errant image. I am running wordpress locally on my computer, using bitnami.

    Any help/ suggestions greatly appreciated.
    Many thanks,
    Tim

    <?php
    /*
    Template name: chiro_template
    */
    ?>
    
    <?php get_header();?>
    
    <div id="mainContent">
    
    <div id="imageHolder">
    <img src='productImages/chiroRollInUse.jpg' width="450" height="356" alt="chiro roll in use"/>
    
    </div>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
        <?php the_content(); ?>
    
    <?php endwhile; endif; ?>
    </div>
    
    <?php /*?><?php get_sidebar(); ?><?php */?>
    
    <?php get_footer(); ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Full image paths are usually safest in theme files.

    If your “productImages” folder is in the root of your theme folder, try this instead:

    <img src='<?php bloginfo('template_directory');?>/productImages/chiroRollInUse.jpg' width="450" height="356" alt="chiro roll in use"/>
    Thread Starter timsig

    (@timsig)

    Thanks so much, that worked like a charm. How could I now adapt this so that the image path is pulled from a custom field on each individual page; can the php part be included in the custom field?

    For a custom field, I THINK you’d want to enter in the full path to the image. So if youre custom field was “Image”, and you entered in https://(path here), then in your template file:

    <?php $image = get_post_meta($post->ID, 'Image', true); ?>
    <img src="<?php echo $image; ?>" alt="" />
    Thread Starter timsig

    (@timsig)

    Thanks Jeezyo, this also works; the problem now is that all the custom fields will need updating when the website is uploaded and running off a web server. Is there a way of combining these two solutions, so that the relative address is pulled from the custom field and added to the
    <?php bloginfo('template_directory');?>

    I guess this amounts to adding one php string to another; I’ve had a go, but the page always goes blank; I think i’m not sufficiently versed in php syntax.
    Many thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘images will not show up’ is closed to new replies.