在引导程序弹出窗口中显示缩略图wordpress



如何在引导程序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();
?>

正如您所说,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.''>">';

最新更新