W
W
WebforSelf2021-03-05 10:57:20
WordPress
WebforSelf, 2021-03-05 10:57:20

Ajax pagination not working on main WP?

There are 2 plugins
WP-PageNavi - popular for displaying pagination
and
WP Ajax Load More Pagination - ajax page loading

It works fine on the archives page, but on the main page it outputs via WP_query

<div id="masonry">

<?php
$args = array(
  'post_type'      => 'post',
  'posts_per_page' => 6,
  'orderby'        => 'date',
  'order'          => 'DESC',
);
$q = new WP_Query($args);
?>

<?php if ( $q->have_posts() ) : ?>
  <?php while ( $q->have_posts() ) : $q->the_post(); ?>
    <div class="item">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </div>
  <?php endwhile; ?>
<?php endif; ?>
</div>

<?php wp_pagenavi( array( 'query' => $q ) ); ?>


As a result, I have pagination and it seems like Ajax is trying to update the records, but when I try to switch to page 2, it remains on 1.

Here is an example of the work of these 2 plugins
Example of the archives page - Tyts
Everything works on the archives page.

But on the main page - Tyts
Ajax is trying to work, but the pages are not scrolling.

6041e457a78e4288456702.png

The selectors are correct.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WebforSelf, 2021-03-05
@WebforSelf

Decision

<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array(
  'post_type'      => 'post',
  'posts_per_page' => 6,
  'orderby'        => 'date',
  'paged' => $paged,
  'order'          => 'DESC',
);
$q = new WP_Query($args);
?>

$paged passes the current page.
On the main
page $paged = (get_query_var('page')) ? get_query_var('page') : 1;
On other pages
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

M
Maxim Yakovlew, 2017-12-12
@serii81

If you are using sass, then the bootstrap.scss file contains the assembly bundle.
_navbar.scss is responsible for styling the navbar.
If you also connect js separately, then jquery + utils + dropdown + collapse is used in the navbar

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question