Wordpress <! - ?php the_post_thumbnail('full'); ? - >没有img-tag

时间:2010-11-14 23:27:31

标签: php wordpress

我注意到在Wordpress中使用post_thumbnail()函数会插入包含img-tag的图像。有没有办法让它只插入该图像的src?

Sofar我试过这个

$image = get_the_post_thumbnail( $post->ID, 'thumbnail' ); echo $image;

但它只是出口相同。 有任何想法吗?在此先感谢您的帮助:))

2 个答案:

答案 0 :(得分:12)

找到答案。不管怎样,谢谢。

<?php
//Get the Thumbnail URL
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array(320,240), false, '' );
echo $src[0];
?>

答案 1 :(得分:0)

缩略图链接到大图像尺寸 此示例链接到“大”后缩略图图像大小,必须在循环中使用。

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>';
}}

来源:https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/