2015-11-02 119 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();循环后,主查询复位。