嗨,我正在尝试将滑块放入我的 wordpress 主题中。这是我到目前为止所拥有的:
<?php
$slider_query = new WP_Query(array(
'posts_per_page'=>'5'
));
if($slider_query->have_posts()):
while($slider_query->have_posts()):
$slider_query->the_post();
if(function_exists('has_post_thumbnail') && has_post_thumbnail()){
the_post_thumbnail();
}
endwhile;
endif;
?>
虽然这确实有效并检索图像,但我需要能够重新检索 url,因为我必须为标题设置不同的标题属性。
有人知道检索缩略图URL的方法吗?
编辑:我也尝试使用
URL$url = wp_get_attachment_image_src(the_post_thumbnail());
但是出于 som 原因,查询返回 10 个链接 img,我只将其设置为 5。奇怪的是,偶数图像没有来源。
尝试使用 wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'wanted-size' );
.(将wanted-size
替换为正确的大小)。
有关get_post_thumbnail_id
的更多信息,请点击此处。