自定义帖子类型问题中的分页

时间:2014-03-20 10:09:49

标签: php wordpress pagination

我遇到了非常奇怪的问题。我做了一个帖子类型“洞察”,现在我想要一个分页(没有插件)。当我点击下一篇文章时,它显示我404错误

这是代码

<?php
        if ( get_query_var('paged') ){
            $paged = get_query_var('paged');
        }
        else {
            $paged = 1;
        }


    query_posts(array('post_type'=>'insight','posts_per_page'=>'1','order'=>'DESC', 'paged' => $paged)); ?>

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

<?php endwhile; ?>

<div class="navigation">
     <div class="alignleft"><?php next_posts_link('&laquo; New Entries') ?></div>
     <div class="alignright"><?php previous_posts_link('&laquo; Older Entries') ?></div>
</div>

我不知道为什么会这样,因为我认为我的代码是正确的。

1 个答案:

答案 0 :(得分:0)

对我的博客我用这个:

的functions.php:

if ( ! function_exists( 'my_pagination' ) ) :
function my_pagination() {
    global $wp_query;

    $big = 999999999; // need an unlikely integer

    echo paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages
    ) );
}
endif;

然后在结束之后,在我想要使用分页的页面中,如类别,索引等...我使用:

<?php endwhile; ?>
<?php my_pagination(); ?>

我希望如果您尝试这会有所帮助:)

修改 - 要查看实际操作,请访问:http://ios-blog.co.uk