Wordpress 如何从WP_Post对象获取图像完整路径?
我想得到图像的完整路径,这样我就可以在image元素的src属性中应用它 我现在得到的是由函数生成的图像:the_post_缩略图();我无法将其应用于图像元素 到目前为止,我所做的是:Wordpress 如何从WP_Post对象获取图像完整路径?,wordpress,Wordpress,我想得到图像的完整路径,这样我就可以在image元素的src属性中应用它 我现在得到的是由函数生成的图像:the_post_缩略图();我无法将其应用于图像元素 到目前为止,我所做的是: <?php $d=get_cat_ID( 'news' ); $catquery = new WP_Query( 'cat='.$d.'&posts_per_page=1&order=DESC' );
<?php
$d=get_cat_ID( 'news' );
$catquery = new WP_Query( 'cat='.$d.'&posts_per_page=1&order=DESC' );
while($catquery->have_posts()) : $catquery->the_post();
the_post_thumbnail();
endwhile;
?>
我想要的是;名称如下的图像路径:
您可以使用
这带来了期望的结果:echo$img_src[0];很高兴帮助你。祝你今天愉快:)
$img_src = wp_get_attachment_image_src( get_post_thumbnail_id($postId) );
$img_src_url = $img_src[0];