I created a custom post type for Products. I can display all the fields no problem (either in a list or a single-product.php). I wanted to use the Media library and associate an uploaded picture with the Product post type (mostly to handle all the thumbnail work automatically). I uploaded a photo to the media library and associated with a specific Product post type.
$args = array(
'label' => __('Products'),
'labels' => $labels,
'public' => true,
'can_export' => true,
'show_ui' => true,
'_builtin' => false,
'capability_type' => 'post',
'menu_icon' => get_bloginfo('template_url').'/functions/images/product.png',
'hierarchical' => false,
'rewrite' => array( "slug" => "product" ),
'supports' => array('title', 'thumbnail'), //MAYBE add thumbnail later!
'show_in_nav_menus' => true
);
I’ve tried everything to display the thumbnail and picture for the Product but it’s not working: the_post_thumbnail();
, get_the_post_thumbnail
but nothing works. Here’s my single-product.php:
<div class="post_content">
<?php
$attachment_args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachment = get_posts($attachment_args); ?>
<img src="<?php echo wp_get_attachment_image_src($attachment->ID, 'full', false); ?>" />
<p><?php echo get_post_meta($post->ID, $prefix.'description', true); ?></p>
<ul>
<?php //this gets the custom fields for the document links (PDF Files)
$custom_field_keys = get_post_custom_keys();
foreach ( $custom_field_keys as $key => $value ) {
$valuet = trim($value);
if ( '_' == $valuet{0} || $prefix != substr($valuet, 0, 4) || $prefix.'description' == $valuet )
continue;
$n = substr($valuet, -1);
if ( $valuet == $prefix.'docname'.$n)
echo '<li><a href="' . get_post_meta($post->ID, $prefix.'docurl'.$n, true) . '" target="_blank">' . get_post_meta($post->ID, $prefix.'docname'.$n, true) . '</a></li>';
}
?>
</ul>
</div><!-- end post_content -->
Am I missing something? Thank you!
the_post_thumbnail()
echoes the full image tag including src, you’re using it within your own image tag. If you want just the thumbnail src to use within your own tag, usewp_get_attachment_image_src
instead.also- unrelated, use
the_title_attribute
for alt and title attributes within tags instead ofthe_title
.EDIT- using
wp_get_attachment_image_src
: