Pagination not working in static page that placed outside of WP directory

I’m having a trouble with my site.

I’ve partially added blog(wp) function into ‘blogs.php’ with code require('./blog/wp-load.php').
This file locates outside of WP installed dir.( reason why doing this is that the main site was already depoloyed.)

Basically the function of WP works by this code.
but, not for paginate function.

Here is my directory tree.


server

-someindex.php

-blogs.php (this is the page to show the posts, and the wp codes here)

-/blog(WP is installed in this dir )


here is my code its in blogs.php.

<?php
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 3,
'paged' => $paged,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish'
);
$the_query = new WP_Query($args);
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();#
?>
<div class="post">
<h1 class="title"><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
<?php endwhile; endif; ?>

<?php
if ($the_query->max_num_pages > 1) { 
echo paginate_links(array(
'base' => '%_%',
'format' => '?page=%#%',
'current' => max(1, $paged),
'total' => $the_query->max_num_pages
));
}
?>
<?php wp_reset_postdata(); ?>

This code produces all the posts, and paginate href link like http://hoge/blogs?=2 to next page.
Seems working well.

But, I’m stuck here.
when I jump to the next page, page jumps, The site calls the link properly, I can see the exact url in address bar, don’t see any errors like 404, But, the contents doesn’t change. The posts which was in 1st page is still in there. Why not showing the 2nd pg?

As you can see from this result, the paginate is not passing the information to the next link.

I’ve been working all day to solve this issue.
Then I found some article says ‘wp-load.php’ does not support the paginate.

and Now, Oh Jesus, What should I do.

I need your help.
Thank you.

Read more here: Pagination not working in static page that placed outside of WP directory

Leave a Reply

Your email address will not be published. Required fields are marked *