【问题标题】:display thumbnail wordpress in bootstrap popover在引导弹出窗口中显示缩略图 wordpress
【发布时间】:2013-07-29 12:32:15
【问题描述】:
如何在引导弹出窗口中显示缩略图?
我使用了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();
?>
【问题讨论】:
标签:
wordpress
twitter-bootstrap
thumbnails
popover
【解决方案1】:
正如你所说,the_post_thumbnail() 固有地回显整个<img> 标签,所以当你回显它时它会做意想不到的事情。改为这样做:
echo '<a href="'.get_permalink().'" rel="popover" data-title="'.get_the_title().'" data-content="';
the_post_thumbnail('full');
echo '">';
您现在很有可能会遇到 Wordpress 为您提供的 <img> 元素中未转义的双引号的问题,因此仅获取缩略图 URL 可能更有意义:
$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.'\'>">';