我为产品创建了自定义帖子类型。我可以毫无问题地显示所有字段(在列表或单个product.php中)。我想使用媒体库,将上传的图片与产品帖子类型关联起来(主要是自动处理所有缩略图工作)。我将一张照片上传到媒体库,并与特定的产品帖子类型相关联。
$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
);
我尝试了各种方法来显示产品的缩略图和图片,但都不起作用:
the_post_thumbnail();
,
get_the_post_thumbnail
但什么都不管用。这是我的单一产品。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 -->
我错过什么了吗?非常感谢。