自定义文章类型分页回报404

问题描述 投票:0回答:1

我试图做一个分页在我的CPT,但它不工作。浏览器返回了我一个404错误与链接CPT /页/ 2。我有这个在我的代码:

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插件,我只需要一个去完成它。

非常感谢你!

wordpress plugins pagination
1个回答
0
投票

嘿,我想你的代码,它工作正常,请尽量保存您的永久链接在设置>永久链接,然后保存更改

© www.soinside.com 2019 - 2024. All rights reserved.