开发者

enabling pagination inside wordpress post

开发者 https://www.devze.com 2023-01-10 12:28 出处:网络
i have a specific single page which display a single post. the thing is that i want to display below it all the other posts which have the same special meta data and i made that to work as well.

i have a specific single page which display a single post. the thing is that i want to display below it all the other posts which have the same special meta data and i made that to work as well.

the problem starts when i try to make pagination to the list of the posts below.

the single post url is something like that:

blog.com/somepost

and the pagination link to the second page of posts below looks someting like this

blog.com/somepost/page/2

and wordpress automatically redirects me back to

blog.com/somepost

how can i prevent it from redirecting me back?

btw, i"m using something like that:

i"m doing something like this:

while( have_posts() ):  the_post();

   //here printing the single post          

endwhile;

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;


$args = array(
   'meta_key' => '_btree_project_id',
   'meta_value' => $post->ID,
   'post_status' =开发者_如何学C> 'publish',
   'paged' => $paged,
   'posts_per_page' => 8
);

$temp = $wp_query;

$wp_query = new WP_Query( $args );

while( have_posts() ): the_post();

   //looping through the related posts here 

endwhile;


The reading I've done about WordPress pagination gives me the impression that it is an imperfect feature. It requires the global var $wp_query which stems from the WP_Query object. WP_Query holds the global $wp_query which is necessary for making even basic pagination work. Custom queryies don't have access to $wp_query, nor do they own a var to control pagination. I assume you are using a custom query to grab that single post, and as this article points out, with custom queryies:

the “fix” is to trick WordPress into using the global $wp_query variable when using our own custom loops.

The article gives an example of utiilizing the global var in your custom query so that you have access to the query_vars that make pagination possible.

I expect that your permalink structure and a custom query that I'm guessing you are using might not be working because the global $wp_query var isn't available during your loop to show related posts.

What does your code to get, display, and paginate the related posts look like? Can you post?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号