Support » Themes and Templates » Pull URL from Custom Field on a page without repetition

  • Resolved keithiopian

    (@keithiopian)


    My home page has an image which populates via a URL inserted into the custom field I’ve created. My snippet of code is displaying my img tag 3 times, first 2 with no src, (i.e. <img src with=900>), and the 3rd properly. It even eliminats the equals sign and the 2 double quotes. This is the snippet I am referring to:

    <main id="home">
    	<?php query_posts('post_type=page'); ?>
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        	<img id="showcase" src="<?php echo get_post_meta($post->ID, 'Main Home Page Image',true); ?>" width="900">
    	<?php endwhile; ?>
            <?php else : ?>
            <h2>Not Found</h2>
    	<?php endif; ?>
            <?php wp_reset_query(); ?>
        </main>

    When this renders in the browser, I get 2 blank squares and the 3rd is the image I want. Source code when rendered looks like this:

    <img id="showcase" src width="900">
    <img id="showcase" src width="900">
    <img id="showcase" src="http://localhost/wp-content/uploads/2014/04/index.jpg" width="900">

    I am simply looking to pull the URL once and have it populate the image. Again, this is coming from a page not a post. Can anyone offer me some insight?

  • The topic ‘Pull URL from Custom Field on a page without repetition’ is closed to new replies.