WordPress破碎分页

问题描述:

我的自定义帖子页面的分页工作正常,但添加几个帖子后它坏了 - 旧的帖子链接不再工作。WordPress破碎分页

请问我该如何解决?我曾尝试禁用插件,更改永久链接以及几乎所有我可以在WordPress Codex上轻松找到的内容。

这里是我的查询与分页:

<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
$args = array('post_type' => 'press' , 'posts_per_page' => 50 , 'paged' => $paged); 
query_posts($args); 
/*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts) */ 
//query_posts ($args);//query_posts($query_string . '&caller_get_posts=6&posts_per_page=12'); 
?> 
<ul class="griditemleft clear"> 
    <?php if(have_posts()) : while(have_posts()) : the_post(); ?> 
     <?php if (has_post_thumbnail()) : ?> 
      <li> 
       <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumbnail'); ?></a> 
       <h2 class="press-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> 
      </li> 
     <?php endif; ?> 
    <?php endwhile; ?> 
</ul> 

<div class="nav-previous alignleft"><?php next_posts_link('Older posts'); ?></div> 
<div class="nav-next alignright"><?php previous_posts_link('Newer posts'); ?></div> 

<?php else : ?> 
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> 
<?php endif; ?> 

它并不完全是你想达到什么明确的,但我想你想在http://codex.wordpress.org/Making_Custom_Queries_using_Offset_and_Pagination

在查询中指定硬编码的偏移密切关注可以和将打破分页,因为WordPress内部使用偏移来计算和处理分页。

要解决此限制,您需要编写一些其他代码来手动处理分页;您需要检测循环是否有其他页面,然后为当前页面动态计算适当的偏移量。

控制自定义分页的代码将全部出现在您的functions.php文件中,而不是在模板page.php中。您可以设置初始偏移量,并重新定义每页的帖子数。在上面的代码链接上显示了特定的样本。

你会被添加动作查询运行之前,通过

add_action('pre_get_posts', 'myprefix_query_offset', 1); 

,你将不得不通过

add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2); 
占定制