如何使用 get_the_post_thumbnail();对于次要特色图片
How to use get_the_post_thumbnail(); for a secondary featured image
我的 wordpress 自定义 post 类型产品上有两张特色图片。
我用这个代码注册了次图:
if (class_exists('MultiPostThumbnails')) {
new MultiPostThumbnails(
array(
'label' => 'Secondary Image',
'id' => 'secondary-image',
'post_type' => 'product'
)
);
}
现在我要调用副图。使用此函数成功调用产品图片 echo get_the_post_thumbnail( $_product->id);
但是,我无法操纵该 wordpress 函数来获取自定义次要图像。我也试过 the_post_thumbnail();
但没有成功,还没有找到另一种方法来获取它。
编辑:
为了清楚起见,我想在不同的页面上呼应次要图像。我尝试使用带有 $_product->id
的产品 ID 来隔离特定的 post 这张图片也相关,但是,所有可用的 wordpress 函数只能获取产品图片,我一辈子都无法获得其他图片:(
它在 FAQ
注册新的缩略图尺寸(可选)
add_image_size('post-secondary-image-thumbnail', 250, 150);
然后在你的主题中:
MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image', NULL, 'post-secondary-image-thumbnail');
编辑
根据修改后的问题,要在循环外调用图像,因此您需要自己指定一个 ID,您需要使用 get_the_post_thumbnail()
方法。
MultiPostThumbnails::get_the_post_thumbnail(
'product,
'secondary-image',
$product->id,
'post-secondary-image-thumbnail',
null
)
我的 wordpress 自定义 post 类型产品上有两张特色图片。
我用这个代码注册了次图:
if (class_exists('MultiPostThumbnails')) {
new MultiPostThumbnails(
array(
'label' => 'Secondary Image',
'id' => 'secondary-image',
'post_type' => 'product'
)
);
}
现在我要调用副图。使用此函数成功调用产品图片 echo get_the_post_thumbnail( $_product->id);
但是,我无法操纵该 wordpress 函数来获取自定义次要图像。我也试过 the_post_thumbnail();
但没有成功,还没有找到另一种方法来获取它。
编辑:
为了清楚起见,我想在不同的页面上呼应次要图像。我尝试使用带有 $_product->id
的产品 ID 来隔离特定的 post 这张图片也相关,但是,所有可用的 wordpress 函数只能获取产品图片,我一辈子都无法获得其他图片:(
它在 FAQ
注册新的缩略图尺寸(可选)
add_image_size('post-secondary-image-thumbnail', 250, 150);
然后在你的主题中:
MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image', NULL, 'post-secondary-image-thumbnail');
编辑
根据修改后的问题,要在循环外调用图像,因此您需要自己指定一个 ID,您需要使用 get_the_post_thumbnail()
方法。
MultiPostThumbnails::get_the_post_thumbnail(
'product,
'secondary-image',
$product->id,
'post-secondary-image-thumbnail',
null
)