自定义帖子类型分页返回404

时间:2019-02-03 15:09:26

标签: wordpress plugins pagination

我正在尝试在CPT中进行分页,但是它不起作用。浏览器通过链接cpt / page / 2向我返回了404错误。我的代码中有这个

get_header(); 
global $wp_query, $wpdb, $paged;

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = [
        'post_type'         => 'viewer',
        'posts_per_page'    => 1,
        'order'             => 'DES',
        'orderby'           => 'date',
        'paged'             => $paged
];

$query = new WP_Query( $args );
?>
<div class="art-container">
    <div class="art-row">
        <?php
        if( $query->have_posts() ) :
            while( $query->have_posts() ) : $query->the_post(); ?>
                <?php
                $post = get_post();
                $post_id = $post->ID;
                $post_title = get_the_title();
                $post_content = get_the_content();
                $post_image_url = get_the_post_thumbnail_url();
                $post_date = get_the_date(); ?>
                <div class="art-slides fade">
                    <div class="art-image" style="background-image: url(<?php echo $post_image_url; ?>)"></div>
                    <div class="art-title"><h2><?php echo $post_title; ?></h2></div>
                    <div class="art-date"><span><?php echo $post_date; ?></span></div>
                    <div class="art-content-block"><p><?php echo $post_content; ?></p></div>
                </div>
            <?php   

            endwhile;?>

            <div class="pagination">
                    <?php                    
                        $big = 999999999; // need an unlikely intege

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

<?php 
get_footer();

请帮助我!我正在开发一个wordpress插件,只需要完成它即可。

非常感谢您!

1 个答案:

答案 0 :(得分:0)

嘿,我尝试过您的代码,它工作正常,请尝试重新保存您的永久链接 设置> 永久链接,然后保存更改