2015-11-02 120 views
0

我搜索了互聯網,但找不到解決方案。我收到404錯誤,當我使用WP pagenavi導航到任何其他頁面,找不到頁面錯誤導航

<ul class="product-items"> 
     <?php 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 

    $args = array(
     'post_type'=>'product', 
     'posts_per_page' => 1, 
     'paged' => $paged 
    ); 

    $product_query = new WP_Query($args); 

    if($product_query->have_posts()) : while($product_query ->have_posts()) : $product_query ->the_post(); 
    $id = get_the_ID(); 

    ?> 


      <li> 
        <a href="<?php the_permalink(); ?>"> 
        <span class="product-img"><?php echo get_the_post_thumbnail($id, array(101,128,true)) ?></span> 
        <span class="product-detail"><?php $title=get_the_title(); echo $trimed=wp_trim_words($title,3) ?></span> 
      </a> 
       </li> 
       <?php endwhile; if(function_exists('wp_pagenavi')) { wp_pagenavi(array('query' => $product_query)); } 

wp_reset_postdata(); ?>

+0

這個'wp_pagenavi($ product_query);'可能是問題所在。評論一下,看看你是否仍然有錯誤信息。並且避免在方法調用中添加空格,這也可能導致問題('$ product_query - > have_posts()'應該是'$ product_query-> have_posts())'。 – vard

+0

感謝隊友回覆,我不會在刪除wp_pagenavi($ product_query)時出錯。但我也沒有得到導航?我需要導航..我也只是刪除空間 – Habib

+0

我只是找到解決方案,取代wp_pagenavi($ product_query);與wp_pagenavi(數組('查詢'=> $ product_query))但現在我得到404導航.. – Habib

回答

1

這是一個真正的邊緣情況下使用query_posts可以有用的,因爲你需要更換,以使您的分頁插件工作的主要查詢。所以你必須給你的查詢改成這樣:

$args = array(
    'post_type'=>'product', 
    'posts_per_page' => 1, 
    'paged' => $paged 
); 

$product_query = new WP_Query($args); 

if(have_posts()): 
    while(have_posts()) : the_post(); 
     $id = get_the_ID(); 
     ?> 
     <li> 
       <a href="<?php the_permalink(); ?>"> 
       <span class="product-img"><?php echo get_the_post_thumbnail($id, array(101,128,true)) ?></span> 
       <span class="product-detail"><?php $title=get_the_title(); echo $trimed=wp_trim_words($title,3) ?></span></a> 
     </li> 
    <?php endwhile; 
    if(function_exists('wp_pagenavi')) { 
     wp_pagenavi(); 
    } 
wp_reset_query(); 
endif; ?> 

這真的很重要的,你使用wp_reset_query();循環後,主查詢復位。