【发布时间】:2015-03-07 02:38:19
【问题描述】:
我在 wordpress 自定义页面中出现分页问题。我用的模板眼花缭乱,这是分页功能:https://github.com/puikinsh/Dazzling/blob/master/inc/template-tags.php 但总是 $GLOBALS['wp_query']->max_num_pages 为 0(空)。我尝试了很多次来改变它,这就是我现在所做的:
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$query_args = array(
'post_type' => 'post',
'category__in' => '4',
'posts_per_page' => 3,
'max_num_pages' => 5,
'paged' => $paged
);
// create a new instance of WP_Query
$the_query = new WP_Query( $query_args );
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); // run the loop ?>
<article>
<h1><?php echo the_title(); ?></h1>
<div class="excerpt">
<?php the_excerpt(); ?>
</div>
</article>
<?php endwhile; ?>
<?php if ($the_query->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?>
<?php dazzling_paging_nav()); ?>
<?php } ?>
<?php else: ?>
<article>
<h1>Sorry...</h1>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
</article>
<?php endif; ?>
我做错了什么?有什么想法吗?
【问题讨论】:
标签: wordpress post pagination