admin管理员组文章数量:1426023
I have the following snippet which adds post thumbnails to products on archive page if matches a given product category, which will output the image but echos the the post id as well. How do I suppress to not show post id?
add_action( 'woocommerce_after_shop_loop_item_title', function () {
if(is_product_category('t-shirts')) {
$thumb = get_the_post_thumbnail( the_ID());
if(is_string($thumb) ) {
echo '<div class="imagewrapper">' . $thumb;
}
}
}, 9 );
add_action( 'woocommerce_after_shop_loop_item_title', function () {
if(is_product_category('t-shirts')) {
$thumb = get_the_post_thumbnail( the_ID());
if(is_string($thumb) ) {
echo '</div>';
}
}
}, 11 );
I have the following snippet which adds post thumbnails to products on archive page if matches a given product category, which will output the image but echos the the post id as well. How do I suppress to not show post id?
add_action( 'woocommerce_after_shop_loop_item_title', function () {
if(is_product_category('t-shirts')) {
$thumb = get_the_post_thumbnail( the_ID());
if(is_string($thumb) ) {
echo '<div class="imagewrapper">' . $thumb;
}
}
}, 9 );
add_action( 'woocommerce_after_shop_loop_item_title', function () {
if(is_product_category('t-shirts')) {
$thumb = get_the_post_thumbnail( the_ID());
if(is_string($thumb) ) {
echo '</div>';
}
}
}, 11 );
Share
Improve this question
asked Jun 17, 2019 at 14:05
fefefefe
8943 gold badges14 silver badges34 bronze badges
1 Answer
Reset to default 2I believe because:
the_ID() : Display the ID of the current item in the WordPress Loop.
and
get_the_ID() : Retrieve the ID of the current item in the WordPress Loop.
So the_ID()
displays the post ID.
Try to use get_the_ID()
本文标签: categorieswhy getthepostthumbnail( theID()) echos extra post id
版权声明:本文标题:categories - why get_the_post_thumbnail( the_ID()) echos extra post id 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745393644a2656715.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论