I create a theme and want to make ajax pagination for my blog page. Actually, from page 1 to 5 its working normally. But why from page 6 to the end of pagination, have 404 not found? If you think, “maybe there is no page 6?”, but actually there is page 6, but I don’t understand why not loaded. This is my index.php file:
<code><?php
get_header();
?>
<div class="container">
<div class="row">
<div class="col-lg-9 col-md-8 col-12">
<div id="postAjax">
<div class="row">
<?php
$paged = max(1, get_query_var('paged', 1));
$query_posts = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 6,
'paged' => $paged
));
if ($query_posts->have_posts()) {
while ($query_posts->have_posts()) : $query_posts->the_post();
?>
<div class="col-lg-6 mb-3">
<article <?php post_class();?>>
<div class="card h-100" style="width: 100%;">
<div style="height: 200px; overflow: hidden; background: rgba(0, 0, 0, 0.3);">
<?php echo get_the_post_thumbnail(get_the_ID(), 'medium', array('class' => 'card-img-top', 'style' => 'object-fit: cover;')); ?>
</div>
<div class="card-body">
<h2 class="card-title h5"><a class="text-decoration-none" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</div>
</div>
</article>
</div>
<?php
endwhile;
?>
<div id="paginationAjax" class="my-4">
<?php
$big = 999999999; // Angka besar untuk memastikan paginasi berfungsi
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => 'page/%#%/',
'current' => $paged,
'total' => $query_posts->max_num_pages
));
?>
</div>
<?php
} else {
?><p>Tidak ada yang dapat ditampilkan</p><?php
}
?>
</div>
</div>
</div>
<?php get_sidebar(); ?>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function($){
$('#postAjax').on('click', '#paginationAjax a', function(e){
e.preventDefault();
var link = $(this).attr('href');
// Placeholder HTML
var placeholderHtml =
'<div class="col-lg-6 mb-3">' +
'<article class="card h-100" style="width: 100%;">' +
'<div style="height: 200px; overflow: hidden; background: rgba(0, 0, 0, 0.3);">' +
'<div class="placeholder-glow">' +
'<div class="placeholder card-img-top" style="width: 100%; height: 200px;"></div>' +
'</div>' +
'</div>' +
'<div class="card-body">' +
'<h2 class="card-title h5 placeholder-glow">' +
'<span class="placeholder col-6"></span>' +
'</h2>' +
'<p class="card-text placeholder-glow">' +
'<span class="placeholder col-7"></span>' +
'<span class="placeholder col-4"></span>' +
'<span class="placeholder col-4"></span>' +
'<span class="placeholder col-6"></span>' +
'<span class="placeholder col-8"></span>' +
'</p>' +
'</div>' +
'</article>' +
'</div>';
// Show placeholders
$('#postAjax .row').html(placeholderHtml.repeat(6));
// Load new content
$('#postAjax').load(link + ' #postAjax > *', function(response, status, xhr) {
if (status == "error") {
console.log("Error: " + xhr.status + " " + xhr.statusText);
}
});
});
});
</script>
<?php get_footer(); ?>
</code>
<code><?php
get_header();
?>
<div class="container">
<div class="row">
<div class="col-lg-9 col-md-8 col-12">
<div id="postAjax">
<div class="row">
<?php
$paged = max(1, get_query_var('paged', 1));
$query_posts = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 6,
'paged' => $paged
));
if ($query_posts->have_posts()) {
while ($query_posts->have_posts()) : $query_posts->the_post();
?>
<div class="col-lg-6 mb-3">
<article <?php post_class();?>>
<div class="card h-100" style="width: 100%;">
<div style="height: 200px; overflow: hidden; background: rgba(0, 0, 0, 0.3);">
<?php echo get_the_post_thumbnail(get_the_ID(), 'medium', array('class' => 'card-img-top', 'style' => 'object-fit: cover;')); ?>
</div>
<div class="card-body">
<h2 class="card-title h5"><a class="text-decoration-none" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</div>
</div>
</article>
</div>
<?php
endwhile;
?>
<div id="paginationAjax" class="my-4">
<?php
$big = 999999999; // Angka besar untuk memastikan paginasi berfungsi
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => 'page/%#%/',
'current' => $paged,
'total' => $query_posts->max_num_pages
));
?>
</div>
<?php
} else {
?><p>Tidak ada yang dapat ditampilkan</p><?php
}
?>
</div>
</div>
</div>
<?php get_sidebar(); ?>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function($){
$('#postAjax').on('click', '#paginationAjax a', function(e){
e.preventDefault();
var link = $(this).attr('href');
// Placeholder HTML
var placeholderHtml =
'<div class="col-lg-6 mb-3">' +
'<article class="card h-100" style="width: 100%;">' +
'<div style="height: 200px; overflow: hidden; background: rgba(0, 0, 0, 0.3);">' +
'<div class="placeholder-glow">' +
'<div class="placeholder card-img-top" style="width: 100%; height: 200px;"></div>' +
'</div>' +
'</div>' +
'<div class="card-body">' +
'<h2 class="card-title h5 placeholder-glow">' +
'<span class="placeholder col-6"></span>' +
'</h2>' +
'<p class="card-text placeholder-glow">' +
'<span class="placeholder col-7"></span>' +
'<span class="placeholder col-4"></span>' +
'<span class="placeholder col-4"></span>' +
'<span class="placeholder col-6"></span>' +
'<span class="placeholder col-8"></span>' +
'</p>' +
'</div>' +
'</article>' +
'</div>';
// Show placeholders
$('#postAjax .row').html(placeholderHtml.repeat(6));
// Load new content
$('#postAjax').load(link + ' #postAjax > *', function(response, status, xhr) {
if (status == "error") {
console.log("Error: " + xhr.status + " " + xhr.statusText);
}
});
});
});
</script>
<?php get_footer(); ?>
</code>
<?php
get_header();
?>
<div class="container">
<div class="row">
<div class="col-lg-9 col-md-8 col-12">
<div id="postAjax">
<div class="row">
<?php
$paged = max(1, get_query_var('paged', 1));
$query_posts = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 6,
'paged' => $paged
));
if ($query_posts->have_posts()) {
while ($query_posts->have_posts()) : $query_posts->the_post();
?>
<div class="col-lg-6 mb-3">
<article <?php post_class();?>>
<div class="card h-100" style="width: 100%;">
<div style="height: 200px; overflow: hidden; background: rgba(0, 0, 0, 0.3);">
<?php echo get_the_post_thumbnail(get_the_ID(), 'medium', array('class' => 'card-img-top', 'style' => 'object-fit: cover;')); ?>
</div>
<div class="card-body">
<h2 class="card-title h5"><a class="text-decoration-none" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</div>
</div>
</article>
</div>
<?php
endwhile;
?>
<div id="paginationAjax" class="my-4">
<?php
$big = 999999999; // Angka besar untuk memastikan paginasi berfungsi
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => 'page/%#%/',
'current' => $paged,
'total' => $query_posts->max_num_pages
));
?>
</div>
<?php
} else {
?><p>Tidak ada yang dapat ditampilkan</p><?php
}
?>
</div>
</div>
</div>
<?php get_sidebar(); ?>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function($){
$('#postAjax').on('click', '#paginationAjax a', function(e){
e.preventDefault();
var link = $(this).attr('href');
// Placeholder HTML
var placeholderHtml =
'<div class="col-lg-6 mb-3">' +
'<article class="card h-100" style="width: 100%;">' +
'<div style="height: 200px; overflow: hidden; background: rgba(0, 0, 0, 0.3);">' +
'<div class="placeholder-glow">' +
'<div class="placeholder card-img-top" style="width: 100%; height: 200px;"></div>' +
'</div>' +
'</div>' +
'<div class="card-body">' +
'<h2 class="card-title h5 placeholder-glow">' +
'<span class="placeholder col-6"></span>' +
'</h2>' +
'<p class="card-text placeholder-glow">' +
'<span class="placeholder col-7"></span>' +
'<span class="placeholder col-4"></span>' +
'<span class="placeholder col-4"></span>' +
'<span class="placeholder col-6"></span>' +
'<span class="placeholder col-8"></span>' +
'</p>' +
'</div>' +
'</article>' +
'</div>';
// Show placeholders
$('#postAjax .row').html(placeholderHtml.repeat(6));
// Load new content
$('#postAjax').load(link + ' #postAjax > *', function(response, status, xhr) {
if (status == "error") {
console.log("Error: " + xhr.status + " " + xhr.statusText);
}
});
});
});
</script>
<?php get_footer(); ?>
the pagination work until the end