2013-04-16 58 views
3

我已經創建了一個自定義的archive.php頁面,在默認的archive.php上添加了一些額外的代碼。我想在該頁面中進行分頁,但我不知道它爲什麼不起作用。自定義archive.php中的分頁

我使用wp-pagenavi插件進行分頁。它顯示當我點擊第二頁時出現的page not found錯誤。爲了更容易理解,我張貼了正在發生的事情的圖像。

下面的圖片是頁面加載時發生的情況。您可以看到我標記爲紅色的網站地址: enter image description here

接下來是我點擊'2'導航到第二頁時會發生什麼情況的圖像。正如你所看到的網址是../?m=201303&paged=2

enter image description here

下面是我使用自定義歸檔頁面的代碼:

<?php 

get_header(); ?> 

<div class="archive_page"> 

<?php 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    $args = array_merge($wp_query->query, 
     array('cat' =>'-1,-8,-9', 
     'posts_per_page'=>'2', 
     'paged' =>$paged)); 
     query_posts($args); 
    ?> 
<?php if (have_posts()) : ?> 

<header class="page-header"> 
<h1 class="page-title"> 
<?php if (is_day()) : ?> 
<?php printf(__('Daily Archives: %s', 'twentyeleven'), '<span>' . get_the_date() . '</span>'); ?> 
<?php elseif (is_month()) : ?> 
<?php printf(__('Monthly Archives: %s', 'twentyeleven'), '<span>' . get_the_date(_x('F Y', 'monthly archives date format', 'twentyeleven')) . '</span>'); ?> 
    <?php elseif (is_year()) : ?> 
<?php printf(__('Yearly Archives: %s', 'twentyeleven'), '<span>' . get_the_date(_x('Y', 'yearly archives date format', 'twentyeleven')) . '</span>'); ?> 
<?php else : ?> 
<?php _e('Blog Archives', 'twentyeleven'); ?> 
    <?php endif; ?> 
</h1> 
    </header> 
<div id="navig"> 
    <?php if (function_exists('wp_pagenavi')){wp_pagenavi();}?> 
</div> 
<?php while (have_posts()) : the_post(); ?> 
<div id="all_posts"> 
    <div id="auth_ava"> 
    <?php echo get_avatar(get_the_author_email(), '65');?> 
    </div> 
    <div class="post_title_archive"> 
    <?php 
    the_title(); 
    ?> 
    </div> 
     <div id="name_date_coment_tag"> 
      <div id="auth_dis_name"> 
     <?php the_author_posts_link();?> 
     </div> 
    <div class="border">|</div> 
    <div id="posted_date_archive"> 
     <?php 
     the_time('F j, Y'); 
     ?> 
    </div> 
    <div class="border">|</div> 
    <div class="categories"> 
     Categories: <?php the_category(', '); ?> 
    </div> 
    <div class="border">|</div> 
    <div id="tags_archive"> 
     <?php 
      the_tags('Tags: ', ', ', '<br />'); 
     ?> 
    </div> 
    </div> 
    </div> 
     <div class="excerpt_archive"> 
    <?php 
     the_excerpt(); 
    ?> 
    </div> 
    <?php endwhile; ?> 
    <div id="navig"> 
     <?php if (function_exists('wp_pagenavi')){wp_pagenavi();}?> 
    </div> 
    <?php else : ?> 
    <article id="post-0" class="post no-results not-found"> 
     <header class="entry-header"> 
    <h1 class="entry-title"><?php _e('Nothing Found', 'twentyeleven'); ?></h1> 
    </header> 
    <div class="entry-content"> 
     <p><?php _e('Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven'); ?></p> 
     <?php get_search_form(); ?> 
     </div> 
    </article> 
     <?php endif; ?> 
    </div> 
<?php get_footer(); ?> 

我是一個長期的問題真的很抱歉。我希望我很清楚自己想要達到的目標。

回答

0

只是以下嘗試:

<?php 
//the query using arguments above 
     $wp_query = new WP_Query($args); 

     //use the query for paging 
     $wp_query->query_vars[ 'paged' ] > 1 ? $current = $wp_query->query_vars[ 'paged' ] : $current = 1; 

     //set the "paginate_links" array to do what we would like it it. Check the codex for examples http://codex.wordpress.org/Function_Reference/paginate_links 
     $pagination = array(
      'base' => @add_query_arg('paged', '%#%'), 
      //'format' => '', 
      'showall' => false, 
      'end_size' => 4, 
      'mid_size' => 4, 
      'total' => $wp_query->max_num_pages, 
      'current' => $current, 
      'type' => 'plain' 
     ); 

     //build the paging links 
     if ($wp_rewrite->using_permalinks()) 
      $pagination[ 'base' ] = user_trailingslashit(trailingslashit(remove_query_arg('s', get_pagenum_link(1))) . 'page/%#%/', 'paged'); 

     //more paging links 
     if (!empty($wp_query->query_vars[ 's' ])) 
      $pagination[ 'add_args' ] = array('s' => get_query_var('s')); 

     //run the query 
     if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); 
?> 

也可參考以下位置:

https://wordpress.stackexchange.com/questions/32100/pagination-on-a-custom-page-template

而且

http://wordpress.org/support/topic/custom-post-type-archive-page-pagination-isnt-working

我認爲這可以幫助您解決您的問題。

+0

即使我將代碼更改爲此,也會顯示相同的問題。 –