[英]Wordpress <?php the_post_thumbnail( 'full' ); ?> without the img-tag
I have noticed that using the post_thumbnail() function in Wordpress inserts the image including the img-tag. 我注意到在Wordpress中使用post_thumbnail()函数会插入包含img标签的图像。 Is there a way to have it insert ONLY the src of that image?
有没有办法让它只插入该图像的src?
Sofar i have tried this Sofar我已经尝试过
$image = get_the_post_thumbnail( $post->ID, 'thumbnail' ); echo $image;
but it just exports the same. 但它只导出相同的内容。 Any ideas?
有任何想法吗? thanks in advance for your help :)
在此先感谢您的帮助 :)
Found answer. 找到答案。 Thanks anyway.
不管怎么说,还是要谢谢你。
<?php
//Get the Thumbnail URL
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array(320,240), false, '' );
echo $src[0];
?>
Post Thumbnail Linking to large Image Size This example links to the “large” Post Thumbnail image size and must be used within The Loop. 后缩略图链接到大图像尺寸本示例链接到“大”后缩略图图像尺寸,必须在“循环”中使用。
if ( has_post_thumbnail() ) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
if ( ! empty( $large_image_url[0] ) ) {
echo '<a href="' . esc_url( $large_image_url[0] ) . '" title="' . the_title_attribute( array( 'echo' => 0 ) ) . '">';
echo get_the_post_thumbnail( $post->ID, 'thumbnail' );
echo '</a>';
}}
Source : https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/ 来源: https : //developer.wordpress.org/reference/functions/get_the_post_thumbnail/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.