简体   繁体   English

WordPress的 <?php the_post_thumbnail( 'full' ); ?> 没有img标签

[英]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.

相关问题 如何在wordpress上修改the_post_thumbnail函数? - How to modify the the_post_thumbnail function on wordpress? WordPress循环中的the_post_thumbnail无法正常工作 - the_post_thumbnail in WordPress Loop wont work 调整the_post_thumbnail的大小以正确拉伸,wordpress - resize the_post_thumbnail to stretch properly, wordpress 在WordPress中使用the_post_thumbnail的问题 - Issues using the_post_thumbnail in wordpress wordpress中the_post_thumbnail和get_the_post_thumbnail之间的区别 - Difference between the_post_thumbnail and get_the_post_thumbnail in wordpress 在PHP中更改the_post_thumbnail的输出 - Change out put of the_post_thumbnail in PHP PHP:无法在“ the_post_thumbnail”的“ title”和“ alt”属性中插入“ the_title()”(Wordpress) - PHP: Can't insert 'the_title()' in “title” & “alt” attributes in 'the_post_thumbnail' (Wordpress) the_post_thumbnail(); 根据 WordPress 中的类别调用帖子时不起作用 - the_post_thumbnail(); not working when calling post based on category in WordPress 在我自己的 wordpress 主题中添加 the_post_thumbnail 作为 CSS 背景 - adding the_post_thumbnail as CSS Background, in my own wordpress theme 使用the_post_thumbnail()图像引导4张卡片可以通过wordpress拉伸以适合自己? - Bootstrap 4 cards with the_post_thumbnail() images Stretch to fit using wordpress?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM