2013-11-25 132 views
0

我的自定義帖子頁面的分頁工作正常,但添加幾個帖子後它壞了 - 舊的帖子鏈接不再工作。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; ?> 

回答

0

它並不完全是你想達到什麼明確的,但我想你想在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); 
佔定製