admin管理员组文章数量:1426338
I am loading posts through ajax and it seems new load produces duplicate posts on archive standard loop. This my code I have tried several methods with $do_not_duplicate
but it seems none worked or I had wrong code in place. This is the code for my standard loop:
<?php
$cats = get_the_category();
$cats_array = array();
if ( ! empty( $cats ) ) {
foreach ( $cats as $cat ) {
$cats_array[] = '<a href="' . get_category_link( $cat->term_id ) . '">' . $cat->name . '</a>';
}
}
$cats_output = ( ! empty( $cats_array ) ) ? ' ' . join( ', ', $cats_array ) : '';
?>
<article <?php post_class( 'loop-post loop-post--standard' ); ?>>
<div class="entry-header">
<div class="container-fluid container-fluid--small">
<div class="d-flex align-items-center mb-2">
<?php echo theme_get_post_categories( null, 'mb-0' ); ?>
</div>
<h2 class="entry-title loop-post__title mb-3"><a href="<?php the_permalink( $post_id ); ?>"><?php the_title(); ?></a></h2>
<?php echo theme_post_meta( true, true, false, false ); ?>
</div>
</div>
<?php if ( has_post_thumbnail() ): ?>
<div class="entry-featured loop-post__image">
<a href="<?php the_permalink(); ?>" data-theme-bg-image>
<?php the_post_thumbnail( 'entry-large' ); ?>
</a>
</div>
<?php endif; ?>
<div class="post-cart__excerpt">
<div class="container-fluid container-fluid--small">
<p class="mb-0"><?php echo get_the_excerpt(); ?></p>
</div>
</div>
</article>
Ajax for loading posts:
jQuery(document).ready(function($) {
const $win = $(window),
$ajaxTrigger = $('.theme-ajax-loader__trigger');
$ajaxTrigger.on('click', function (e) {
e.preventDefault();
let $this = $(this),
buttonText = $this.text(),
$posts = $('.theme-archive__posts');
if ( $posts.length ) {
var page = 2;
$.ajax({
url: themeajax.ajax_url,
type: 'post',
data: {
action: 'theme_ajax_handler',
theme_handler: 'load_more_posts',
theme_ajax_nonce: themeajax.ajax_nonce,
// page: page,
query: themeajax.posts,
page: themeajax.current_page,
layout: 'standard'
},
本文标签: loopDuplicate posts on archive page
版权声明:本文标题:loop - Duplicate posts on archive page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745404466a2657188.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论