Wordpress自定义Post-type分页404 w/ WP-Pagenavi


Wordpress Custom Post-type Pagination 404 w/ WP-Pagenavi

我需要为我正在工作的项目拉两个自定义帖子类型。我将它们作为数组传递给post_type。在前面,它们被分成两个不同的列表类,微笑和广告。它们出现,但分页中断。我已经用%postname%设置了我的永久链接,编辑了页面导航的设置,但仍然读取404。

url的读法应该是/smiles/page/*/,但应该是404。

代码如下:

        <?php 
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $the_query = new WP_Query( array( 
                  'post_type' => array ('smiles','ads'),
                  'order' => 'DESC',
                  'posts_per_page' =>'3',
                  'paged' => $paged ));
        while ( $the_query->have_posts() ) : $the_query->the_post();    
        ?>
            <?php if ($post->post_type == 'smiles') { ?>
            <li class=smile>
                <h3><?php the_author(); ?></h3>
                <a href="<?php the_permalink(); ?>" class=x-fi><img src="<?php echo get_first_image(); ?>" /></a>
                <p><?php the_excerpt(); ?></p>
                <?php echo getPostLikeLink( get_the_ID() ); ?>
                <a href="<?php the_permalink(); ?>">Read More / Comment...</a>
            </li>
            <?php } ?>
            <?php if ($post->post_type == 'ads') { ?>
            <li class=ad>
                <?php the_content(); ?>
            </li>
            <?php } ?>                  
        <?php endwhile; ?>
        </ul>
        <?php wp_pagenavi( array( 'query' => $the_query ) ); wp_reset_query(); ?>
编辑1:

检查了一些帖子。修改$the_query为$wp_query,没有结果

好的,我知道了。

简单的解决方案是删除插件并添加一个自定义函数来处理分页。之后,我将"博客"页面的阅读帖子改为1,并更新了永久链接。然后分页开始工作。

完整解决方案:

显然也
function pagination($pages = '', $range = 2) {  
     $showitems = ($range * 2)+1;  
     global $paged;
     if(empty($paged)) $paged = 1;
     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }   
     if(1 != $pages)
     {
         echo "<div class='pagination'>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";
         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
             }
         }
         if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>";  
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
         echo "</div>'n";
     }
}

archive-smiles.php

<?php   
                $the_query = new WP_Query( array( 
                          'post_type' => array ('smiles','ads'),
                          'order' => 'DESC',
                          'posts_per_page' =>'2',
                          'paged' => $paged
                          ));
                while ( $the_query->have_posts() ) : $the_query->the_post();    
                ?>
                    <?php if ($post->post_type == 'smiles') { ?>
                    <li class=smile>
                        <h3><?php the_author(); ?></h3>
                        <a href="<?php the_permalink(); ?>" class=x-fi><img src="<?php echo get_first_image(); ?>" /></a>
                        <p><?php the_excerpt(); ?></p>
                        <?php echo getPostLikeLink( get_the_ID() ); ?>
                        <a href="<?php the_permalink(); ?>">Read More / Comment...</a>
                    </li>
                    <?php } ?>
                    <?php if ($post->post_type == 'ads') { ?>
                    <li class=ad>
                        <?php the_content(); ?>
                    </li>
                    <?php } ?>                  
                <?php endwhile; ?>
                </ul>
                <?php pagination( $the_query->max_num_pages ); ?>