admin管理员组文章数量:1426783
I have this piece of code
<?php
$loop = new WP_Query(array('post__not_in' => array($latestId),'post_type' => 'post', 'posts_per_page' => 9,'paged' => ( get_query_var('page') ? get_query_var('page') : 1 )));
$i=1;
while ( $loop->have_posts() ) : $loop->the_post();
$image = wp_get_attachment_image_src( get_post_thumbnail_id($recent_posts[0]['ID']), 'full' );
$thumbnailImg=$image[0]?$image[0]:catch_that_image($recent_posts[0]);
?>
That I follow then with
<div
class="post-card__thumb__img h-bg-zoom__img"
style="background-image: url('<?php echo $thumbnailImg; ?>');"></div>
But all I get is the thumbnail from the last written post displayed everywhere (rather than the thumbnail of each specific post).
Something is obviously wrong with my loop. Any help would be greatly appreciated. Thank you!
I have this piece of code
<?php
$loop = new WP_Query(array('post__not_in' => array($latestId),'post_type' => 'post', 'posts_per_page' => 9,'paged' => ( get_query_var('page') ? get_query_var('page') : 1 )));
$i=1;
while ( $loop->have_posts() ) : $loop->the_post();
$image = wp_get_attachment_image_src( get_post_thumbnail_id($recent_posts[0]['ID']), 'full' );
$thumbnailImg=$image[0]?$image[0]:catch_that_image($recent_posts[0]);
?>
That I follow then with
<div
class="post-card__thumb__img h-bg-zoom__img"
style="background-image: url('<?php echo $thumbnailImg; ?>');"></div>
But all I get is the thumbnail from the last written post displayed everywhere (rather than the thumbnail of each specific post).
Something is obviously wrong with my loop. Any help would be greatly appreciated. Thank you!
Share Improve this question asked May 17, 2019 at 0:47 TionebTioneb 31 bronze badge 1 |1 Answer
Reset to default 0I'm guessing the problem is this: $recent_posts[0]['ID']
; and I don't see $recent_posts
being defined in your code, so what exactly is that $recent_posts
and where/how did you define it?:
$image = wp_get_attachment_image_src( get_post_thumbnail_id($recent_posts[0]['ID']), 'full' );
And you're inside The Loop, so you could just call get_post_thumbnail_id()
without having to specify the post ID — or use get_the_ID()
to get the current post's ID:
$image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' ); // use this or below
//$image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full' );
And I think the $thumbnailImg=$image[0]?$image[0]:catch_that_image($recent_posts[0]);
should also be:
$thumbnailImg=$image[0]?$image[0]:catch_that_image( get_the_ID() );
本文标签: post thumbnailsIssue with wordpress thumnailssame thumnail displayed everywhere
版权声明:本文标题:post thumbnails - Issue with wordpress thumnails - same thumnail displayed everywhere 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745485863a2660380.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp_reset_postdata();
at the end of your loop. – rudtek Commented May 17, 2019 at 3:14