wordpress分页没有显示

时间:2015-08-03 07:10:36

标签: php wordpress pagination

我的wordpress页面上有自定义查询。查询如下所示:

$args = array(
  'post_type' => array( 'tworca' ),
  'orderby' => 'title',
  'order' => 'ASC',
  'posts_per_page'=>12,
  'post_parent' => 0
);
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args['paged'] = $paged;
// The Query
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
  while ( $the_query->have_posts() ) {
   $the_query->the_post();
   ... this is content of my query.....
 }
?>
<nav>
  <?php previous_posts_link('&laquo; Newer') ?>
  <?php next_posts_link('Older &raquo;') ?>
  <?php wp_pagenavi(); ?>
  </nav>
 <?php
} else {
  echo 'no results';
}
/* Restore original Post Data */
wp_reset_postdata();
?>

但我的分页没有表现出来。知道为什么吗?我已经阅读了许多类似问题的帖子,但解决方案始终是将'paged'参数添加到wp查询中。我在查询中有这个参数,但没有帮助。

提前感谢您的帮助!

3 个答案:

答案 0 :(得分:1)

试试这个...... `$ paged =(get_query_var('paged'))? get_query_var('paged'):1;             $ args = array(                 'posts_per_page'=&gt; 12,                 'paged'=&gt; $分页,                 'orderby'=&gt; '标题',                 'order'=&gt; 'ASC',                 'post_parent'=&gt; 0,                 'post_status'=&gt; '发布',             );             query_posts($ args);             if(have_posts()){             $ i = 0;                 while(have_posts()){                     the_post();

Your data here you want display like title 标题(); }

                    wp_pagenavi();
                }
                wp_reset_query();
            ?>`

答案 1 :(得分:0)

wp_pagenavi()更改为wp_pagenavi( array( 'query' => $the_query) );

答案 2 :(得分:0)

请尝试将查询对象添加到wp_pagenavi(),这就像是,

wp_pagenavi( array( 'query' => $the_query ) );

参考:http://scribu.net/wordpress/wp-pagenavi/wpn-2-74.html