2014-01-25 43 views
2

我試圖讓WordPress分頁工作。WordPress分頁不起作用Page 2

我已經使用了不同的插件,並嘗試調整pagination.php函數中的代碼無濟於事。

無論我到目前爲止使用的插件或調整,頁面2,3等始終顯示相同的帖子集。

這裏是在pagination.php

<!-- Previous/More Entries -->   
<div class="mdnw_pagination"> 

<?php if(function_exists('wp_paginate')) : 
    wp_paginate(); 
; else : ?> 
<div class="p button"><?php next_posts_link(__('« Previous Posts', 'skeleton')); ?></div> 
<div class="m button"><?php previous_posts_link(__('Next Posts »', 'skeleton')); ?></div> 
<?php endif; ?> 

</div> 
<!-- </Previous/More Entries --> 

下面的代碼被用於主頁博客模板代碼:

<!-- THE POST QUERY --> 
         <?php 

        wp_reset_query(); 

        global $paged; 
        global $template_file; 
        $cat_string = ''; 
        $format = ''; 

        if(get_post_custom_values('blog_post_count')) : 
         $post_array = get_post_custom_values('blog_post_count'); 
         $post_count = join(',', $post_array); 
        else : 
         $post_count = -1; 
        endif; 

        /* Get Category Filter */ 
        if(get_custom_field('blog_category_filter')) : 
         $cats = get_custom_field('blog_category_filter'); 
         foreach ($cats as $cat) { 
          $acats[] = $cat;     
         } 
         $cat_string = join(',', $acats);      
        endif; 

        $args=array(
         'cat'=>$cat_string,   // Query for the cat ID's (because you can't use multiple names or slugs... crazy WP!) 
         'posts_per_page'=>$post_count, // Set a posts per page limit 
         'paged'=>$paged,    // Basic pagination stuff. 
         ); 

        query_posts($args); ?> 

        <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 

         <?php get_template_part('includes/format', $format); ?> 

        <?php endwhile; else: ?> 

         <div class="post"> 
           <p><?php _e('Sorry, no posts matched your criteria.', 'skeleton') ?></p> 
         </div><!-- /.post --> 

        <?php endif; ?> 
        <?php get_template_part('includes/element', 'pagination'); ?>      
        <?php wp_reset_query(); ?>     

       </div> 

我應該在任何文件中更改得到它顯示任何其他內容,但第一頁?

我會更改閱讀窗格設置,但查詢帖子功能使用我不知道的動態值。

如何改變或改變它以使其工作?

我試圖https://wordpress.stackexchange.com/questions/105977/wordpress-pagination-not-working-always-showing-first-pages-content此頁面上的解決辦法,但無濟於事:

這是我改變了代碼:

<?php 

        wp_reset_query(); 

        global $paged; 
        global $template_file; 
        $cat_string = ''; 
        $format = ''; 

        if(get_post_custom_values('blog_post_count')) : 
         $post_array = get_post_custom_values('blog_post_count'); 
         $post_count = join(',', $post_array); 
        else : 
         $post_count = -1; 
        endif; 

        /* Get Category Filter */ 
        if(get_custom_field('blog_category_filter')) : 
         $cats = get_custom_field('blog_category_filter'); 
         foreach ($cats as $cat) { 
          $acats[] = $cat;     
         } 
         $cat_string = join(',', $acats);      
        endif; 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
        $args=array(
         'cat'=>$cat_string,   // Query for the cat ID's (because you can't use multiple names or slugs... crazy WP!) 
         'posts_per_page'=> 9, // Set a posts per page limit 
         'paged'=>$paged,    // Basic pagination stuff. 
         ); 

        $your_query = new WP_Query($args); ?> 

        <?php if ($your_query->have_posts()) : while ($your_query->have_posts()) : $your_query->the_post(); ?> 

         <?php get_template_part('includes/format', $format); ?> 

        <?php endwhile; else: ?> 

         <div class="post"> 
           <p><?php _e('Sorry, no posts matched your criteria.', 'skeleton') ?></p> 
         </div><!-- /.post --> 

        <?php endif; ?> 
        <?php get_template_part('includes/element', 'pagination'); ?>      
        <?php wp_reset_query(); ?> 

回答

4

我固定它。

,我發現這裏的修復: http://themeforest.net/forums/thread/pagination-on-wordpress-static-page-set-to-front-page/28120

而不是做這個的:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    query_posts(array('post_type' => 'post', 'paged' => $paged)); 

我這樣做:

if (get_query_var('paged')) { 

$paged = get_query_var('paged'); 

} elseif (get_query_var('page')) { 

$paged = get_query_var('page'); 

} else { 

    $paged = 1; 

} 

query_posts(array('post_type' => 'post', 'paged' => $paged)); 

現在,它的作品!

0

如果我在新主題之間存在差距,我經常會忘記這個分頁問題,​​不得不花一個小時記住我是如何爲自己糾正它的。

我的方法是把所有的查詢選項放在functions.php而不是頁面上。

例如,如果使用分頁,像這樣啓動您的index.php循環會產生頁面2與頁面1相同的錯誤。

<?php 
$args = array('post_type' => 'post', 'posts_per_page' => 4, 'orderby' => 'date', 'order' => 'DESC', 'tag' => 'pics, vids'); 
$loop = new WP_Query($args); 
while ($loop->have_posts()) : $loop->the_post(); 
?> 

因此改變,只是默認的無裝飾圈揭幕戰這樣的..

<?php while (have_posts()) : the_post(); ?> 

,然後把這些相同的選項中的functions.php所以它會是這個樣子..

function modify_query_order_index($query) { 
    if ($query->is_front_page() && $query->is_main_query() && !is_admin()) { 
     $query->set('orderby', 'date'); 
     $query->set('order', 'DESC'); 
     $query->set('posts_per_page', '4'); 
     $query->set('post_type', 'post'); 
     $query->set('tag', 'pics, vids'); 
    } 
} 
add_action('pre_get_posts', 'modify_query_order_index'); 

現在取決於您的分頁功能是如何編寫的,您的頁面1,2和3+應該按預期行事。

獎金

調整posts_per_page與此查詢的功能,而在頁面的設置每頁的職位查詢沒有按將覆蓋管理面板> /設置/讀/ 博客網頁顯示最多 XX設置不會覆蓋該設置。