Took over a project, and one of the errors is the featured images (and certain others rendered in a similar way) are duplicating themselves and replacing the next image thumbnail.
<a href="<?php echo get_permalink(); ?>" class="snack__thumb snack__thumb--featured" style="background-image:url('<?php echo get_the_post_thumbnail_url( $post->ID, 'medium' ); ?>');">
<?php
if (has_category('whitepaper')) { ?>
<div class="snack__banner"><span>whitepaper</span></div>
<?php
}
?>
I've read that not ending a loop with something like wp_reset_postdata(); can cause this type of error however I haven't been able to get it solved.
Relevant plugins installed are
NS Featured Posts
Ajax-Load-More
(Error happening within Load-more field)
This happens on the home page as well in this loop
<?php while ($latest_posts->have_posts()) : ?>
<div class="col-md-4">
?php
$latest_posts->the_post();
include(locate_template('loop-templates/content-snack.php'));
?>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
<?php
if ($latest_posts->max_num_pages > 1) {
echo(do_shortcode('[ajax_load_more id="posts-loader" container_type="div" post_type="post" posts_per_page="6" post_format="standard" pause="true" post__not_in="'.implode(",",$special_ids).'" scroll="false" transition_container_classes="row" button_label="See more posts"]'));
}
?>
Took over a project, and one of the errors is the featured images (and certain others rendered in a similar way) are duplicating themselves and replacing the next image thumbnail.
<a href="<?php echo get_permalink(); ?>" class="snack__thumb snack__thumb--featured" style="background-image:url('<?php echo get_the_post_thumbnail_url( $post->ID, 'medium' ); ?>');">
<?php
if (has_category('whitepaper')) { ?>
<div class="snack__banner"><span>whitepaper</span></div>
<?php
}
?>
I've read that not ending a loop with something like wp_reset_postdata(); can cause this type of error however I haven't been able to get it solved.
Relevant plugins installed are
NS Featured Posts
Ajax-Load-More
(Error happening within Load-more field)
This happens on the home page as well in this loop
<?php while ($latest_posts->have_posts()) : ?>
<div class="col-md-4">
?php
$latest_posts->the_post();
include(locate_template('loop-templates/content-snack.php'));
?>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
<?php
if ($latest_posts->max_num_pages > 1) {
echo(do_shortcode('[ajax_load_more id="posts-loader" container_type="div" post_type="post" posts_per_page="6" post_format="standard" pause="true" post__not_in="'.implode(",",$special_ids).'" scroll="false" transition_container_classes="row" button_label="See more posts"]'));
}
?>
Share
Improve this question
edited Jul 5, 2019 at 2:22
Ranson Namba
asked Jul 5, 2019 at 0:26
Ranson NambaRanson Namba
11 bronze badge
2
- Hey Ranson Namba, can you include a more complete snippet of code. Your current code doesn't really tell us anything. If the issue is with your main loop show us that. If it's a custom loop, show that. And can you give more context around your issue? Is this a single post? An archive? Is javascript or the load more plugin causing this? Have you tried deactivating that plugin? Or turning javascript off? – ngearing Commented Jul 5, 2019 at 0:49
- Updated with more code. I don't believe that a custom loop has been created. This is mainly in a plugin ajax-load-more, the developer said that it can be an error in the repeater template, or queries higher up not being reset with wp_reset_query() – Ranson Namba Commented Jul 5, 2019 at 2:04
1 Answer
Reset to default 0This was due to having an inline <?php $post = get_post()?>
After moving this out and making it global, images stopped duplicating.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745343582a4623442.html
评论列表(0条)