2013-07-29 77 views
1

如何在bootstrap popover中顯示縮略圖wordpress?在bootstrap popover中顯示縮略圖wordpress

我用the_post_thumbnail但這個功能固有地回聲<img>。至於你說的產生的圖像不酥料餅

<?php 
if (have_posts()) : while (have_posts()) : the_post(); 

/*********display the_post_thumbnail in data-content of popover *********/ 

echo '<a href="'.get_permalink().'" rel="popover" data-title="'.get_the_title().'" data-content="'.the_post_thumbnail('full').'">'; 


the_title(); 
echo '</a>'; 
endwhile; endif; 
wp_reset_query(); 
?> 

回答

1

所示,the_post_thumbnail()內在呼應了整個<img>標籤,所以當你迴音它會做意想不到的事情。做到這一點,而不是:

echo '<a href="'.get_permalink().'" rel="popover" data-title="'.get_the_title().'" data-content="'; 
the_post_thumbnail('full'); 
echo '">'; 

有一個非常好的機會,你現在必須在<img>元素與轉義雙引號的問題是WordPress的給你,所以它可能會更有意義,只是讓縮略圖網址:

$thumb = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'full'); 
$url = $thumb['0']; 


echo '<a href="'.get_permalink().'" rel="popover" data-title="'.get_the_title().'" data-content="<img src=\''.$url.'\'>">';