如何获取 WordPress 帖子特色图片 URL [英] How to get WordPress post featured image URL
本文介绍了如何获取 WordPress 帖子特色图片 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此功能来获取特色图片:
<?php the_post_thumbnail('缩略图');?></a>
现在我想通过点击锚标签获得完整的特色图片,我需要在
中提供特色图片网址
我该如何解决这个问题?
解决方案
检查下面的代码,让我知道它是否适合您.
ID) ): ?><?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );?><div id="custom-bg" style="background-image: url('<?php echo $image[0]; ?>')">
<?php endif;?>
I am using this function to get the featured images:
<a href="#" rel="prettyPhoto">
<?php the_post_thumbnail('thumbnail'); ?>
</a>
Now I want to get the full featured image on click on the anchor tag for which I need a featured image URL in
<a href="here" rel="prettyPhoto">
How can I fix this?
解决方案
Check the code below and let me know if it works for you.
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<div id="custom-bg" style="background-image: url('<?php echo $image[0]; ?>')">
</div>
<?php endif; ?>
这篇关于如何获取 WordPress 帖子特色图片 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文