So a few things…
the_title()
gets the title, but it includes mark-up, so when you use that in the title
attribute it actually prints the code out with mark-up around it, like <h1>The Title</h1>
which then breaks out of the title=""
.
So the correct method for that would be:
<a href="<?php the_permalink() ?>" title="<?php echo get_the_title(); ?>">
That’s why you’re getting duplicate titles displaying.
For the rest, this should do it:
<?php
$thumb = tube_getcustomfield( 'wtp_thumb_url', get_the_ID() );
if( !empty( $thumb ) ) { :
echo '<img src="' . $thumb . '" alt="' . get_the_title() . '" title="' . get_the_title() . '" width="240" height="180" class="thumb" />';
else :
//If parent theme use this:
echo '<img src="' . get_template_directory_uri() . '/images/pic_post1.jpg" alt="' . get_the_title() . '" title="' . get_the_title() . '" class="thumb"/>';
//If child theme use this:
//echo '<img src="' . get_stylesheet_directory_uri() . '/images/pic_post1.jpg" alt="' . get_the_title() . '" title="' . get_the_title() . '" class="thumb"/>';
endif;
?>
I’m not sure if you’re using a parent or child theme so I included options for either, just change which echo line is included/uncommented.
I don’t know what the tube_getcustomfield( 'wtp_thumb_url', get_the_ID() )
returns, so maybe try a var_dump right after that line to make sure it’s a full path to the attached image:
var_dump( $thumb );
If it’s not a path like http://domain.com/wp-content/uploads/the-image-you-attached.png
then you’ll need to address that as well.