[英]Wordpress Featured Image URL
我正在嘗試將特色圖片網址添加到特色圖片中,因此點擊該圖片后,它將在燈箱中打開。
我的代碼是:
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<a href="#" target="_blank"><?php if ( has_post_thumbnail() ) { the_post_thumbnail();} ?></a>
<?php endwhile; ?>
<?php else: ?>
<article>
<h1><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h1>
</article><!--/ Article -->
<?php endif; ?>
我已經嘗試了很多事情,但無法獲取縮略圖網址。 我嘗試將這些添加到鏈接#所在的位置:
wp_get_attachment_thumb_url( get_post_thumbnail_id( $post->ID ));
...
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) );
...
<?php echo $thumbnailsrc ?>
我確信還有一個簡單的解決方案尚未找到。 感謝任何可能能夠幫助您的人:-)
請嘗試將此代碼添加到您的發布循環中。 並確認您已為您列出的帖子設置了功能圖片。
<?php $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
if(!empty($post_thumbnail_id)) {
$img_ar = wp_get_attachment_image_src( $post_thumbnail_id, 'full' ); ?>
<img src="<?php echo $img_ar[0];?>" />
<?php } ?>
嘗試這個:
wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' )[0]
假設您在The Loop中 ,則只需使用get_post_thumbnail_id()
即可獲取當前帖子的特色圖片ID。 您還需要傳遞第二個full
參數,以獲取燈箱光源的圖像未調整大小版本。 如果願意,也可以將其限制為大。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.