• Resolved macoD

    (@macod)


    I have problem with echo.
    This code:

    <?php
    if ( get_post_meta($post->ID, 'price', true) )
    {
     	echo '<a href="'.get_post_meta($post->ID, 'price', true).'">'.the_post_thumbnail('slider')."</a>";
    }
    else
    {
       echo the_post_thumbnail('slider');
    }
    ?>

    generate :
    <img width="730" height="280" src="http://localhost/wordpress/wp-content/uploads/2011/04/reel_1.jpg" class="attachment-slider wp-post-image" alt="reel_1" title="reel_1" /><a href="http://localhost/wordpress/portfolios/project-1/"></a>

    but should:
    <a href="http://localhost/wordpress/portfolios/project-1/"><img width="730" height="280" src="http://localhost/wordpress/wp-content/uploads/2011/04/reel_1.jpg" class="attachment-slider wp-post-image" alt="reel_1" title="reel_1" /></a>

    Please help, thx.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    echo '<a href="'.get_post_meta($post->ID, 'price', true).'">'.the_post_thumbnail('slider')."</a>";

    You seem to be mixing ‘ and ” in there. Try this:

    echo '<a href="'.get_post_meta($post->ID, 'price', true).'">'.the_post_thumbnail('slider').'</a>';
    Michael

    (@alchymyth)

    the_post_thumbnail() does not return the image code, as you would need for your code snippet.

    try:

    <?php
    if ( get_post_meta($post->ID, 'price', true) )
    {
     	echo '<a href="'.get_post_meta($post->ID, 'price', true).'">'; the_post_thumbnail('slider'); echo "</a>";
    }
    else
    {
       the_post_thumbnail('slider');
    }
    ?>
    Thread Starter macoD

    (@macod)

    Alchymyth,
    thank you, this works.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Problem with echo’ is closed to new replies.