在模板页面循环中,从名为raspee的标记获取帖子,每页帖子数为5。分页显示在页面中,但不起作用。。
What is problem in my code??
模板页面
<?php /* Template Name: Raspee */ ?>
<?php get_header(); ?>
<?php
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$original_query = $wp_query;
$wp_query = null;
$args=array(\'posts_per_page\'=>5 , \'tag\' => raspee );
$wp_query = new WP_Query( $args );
if ( have_posts() ) :
while (have_posts()) : the_post();
get_template_part(\'content\');
endwhile;
next_posts_link();
previous_posts_link();
endif;
$wp_query = null;
$wp_query = $original_query;
wp_reset_postdata();
?>
<?php get_footer(); ?>
最合适的回答,由SO网友:Navin Bhudiya 整理而成
您没有在WP\\u Query args数组中添加“paged”,这就是分页不起作用的原因。试试这个代码,它肯定会有用的
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$original_query = $wp_query;
$wp_query = null;
$args=array(\'posts_per_page\'=>5, \'tag\' => \'raspee\', \'paged\'=>$paged);
$wp_query = new WP_Query( $args );