Php wp_查询中的分页

Php wp_查询中的分页,php,wordpress,Php,Wordpress,这可能是一个简单的问题,但我无法解决。我已经找了好几个小时了,对我的处境一无所知。我需要使用分页来处理我的_查询 <?php $count = 0; $id_suffix = 1; $items_per_row = 4; $quality = 90; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $wp_que

这可能是一个简单的问题,但我无法解决。我已经找了好几个小时了,对我的处境一无所知。我需要使用分页来处理我的_查询

    <?php   
    $count = 0;
    $id_suffix = 1;
    $items_per_row = 4;
    $quality = 90;      
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;             
    $wp_query = new WP_Query( array( 'posts_per_page' => '4', 'post_type' => 'portfolio') );
    $grid_class = 'grid_3';
    $desired_width = 220;
    $desired_height = 190;
    $terms = get_terms( 'portfolio_categories' ); 
    $count_terms = count( $terms ); 
?>

//some php code 

<?php while ( $wp_query -> have_posts()) : $wp_query -> the_post(); //query the "portfolio" custom post type for portfolio items ?>


//some more php code 


<?php endwhile;?>
<div class="nav-previous"><?php next_posts_link(__('<span class="meta-nav">&laquo;</span> Older posts', 'thematic')) ?></div>
<div class="nav-next"><?php previous_posts_link(__('Newer posts <span class="meta-nav">&raquo;</span>', 'thematic')) ?></div>
</ul>

//一些php代码
//更多的php代码

您正在构造
$paged
变量,但没有使用它

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;             
$wp_query = new WP_Query( 
  array( 
  'posts_per_page' => '4', 
  'post_type' => 'portfolio',
  'paged' => $paged // this is the missing part
) );

WordPress使用
$wp\u查询
变量名。你可能应该换一个。

谢谢@maiorano84和@s_ha_dum为我指明了正确的方向。我想为任何遇到这个问题的人更新这篇文章。我遇到的问题是如何在静态首页上进行分页。读了抄本后,我发现了我的问题

而不是
$paged=(get_query_var('paged'))?获取查询变量('paged'):1
我不得不使用
$paged=(获取查询变量('page'))?获取查询变量(“页面”):1

这一个小小的错误就是使分页保持工作的原因。最后的代码是这样的

<?php   
    $count = 0;
    $id_suffix = 1;
    $items_per_row = 4;
    $quality = 90;
    $paged = (get_query_var('page')) ? get_query_var('page') : 1;
    $my_query = new WP_Query( array( 
    'posts_per_page' => 8, 
    'post_type' => 'portfolio',
    'paged' => $paged
    ) );
    $grid_class = 'grid_3';
    $desired_width = 220;
    $desired_height = 190;
    $terms = get_terms( 'portfolio_categories' ); 
    $count_terms = count( $terms ); 
?>

//一些php代码

<?php while ( $my_query -> have_posts()) : $my_query -> the_post(); //query the "portfolio" custom post type for portfolio items ?>


  (Some more php code)

<?php endwhile;
wp_pagenavi(array( 'query' => $my_query ) );    ?>
</ul><!-- END .portfolio-gallery -->

(更多php代码)


?>

你比我抢先一步。我本来打算建议使用offset参数,但是你的方法更好。另外,是的,将实例名称从$wp_query更改为其他名称是必要的。感谢您的帮助,但我也遇到了同样的问题(分页不更改组合项)。顺便说一句,我将
$wp_query
更改为
$my_query
,现在分页已完全取消。如有任何其他帮助,将不胜感激。我被文件夹下面显示的页面卡住了,但当点击时,它只显示原来的4个项目,无论点击哪个页面。