Why my pagination gets 404?

时间:2020-04-27 作者:D_P

我试图理解为什么我的分页从第二页开始,每页都会出现404错误。现在在我设置的阅读设置中Blog pages show at most 至1。

<?php
    $paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
    $query = new WP_Query(
        array(
            \'post_type\'     => \'behold_testimonials\',
            \'orderby\'       => \'rand\',
            \'paged\'         => $paged
        )
    );

    if ($query->have_posts()):
        while ($query->have_posts()): $query->the_post();
            include( locate_template( \'/elements/testimonials-thumbnail.php\', false, false ) );
        endwhile;
    ?>

        <div class="l-pagination">

        <?php
            // kirki settings
            $pagination_layout = get_theme_mod( \'posts_general__pagination-style\', true );
            if( \'layout-1\' == $pagination_layout ) {
                $pagination_layout_style = \'pagination-1\';
            } elseif( \'layout-2\' == $pagination_layout ) {
                $pagination_layout_style = \'pagination-2\';
            }
        ?>

            <div class="c-pagination <?php echo $pagination_layout_style; ?>">

            <?php
            $total_pages = $query->max_num_pages;
                echo paginate_links( array(
                    \'base\'          => str_replace( 999999999, \'%#%\', esc_url( get_pagenum_link( 999999999 ) ) ),
                    \'format\'        => \'?paged=%#%\',
                    \'total\'         => $total_pages,
                    \'current\'       => max(1, get_query_var(\'paged\')),
                    \'prev_text\'     => __( \'<i class="fas fa-caret-left"></i>\', \'behold-standard\' ),
                    \'next_text\'     => __( \'<i class="fas fa-caret-right"></i>\', \'behold-standard\' ),
                ) );
            ?>

            </div>

        </div>

    <?php
        wp_reset_postdata();
    endif;

?>
我的错在哪里?

1 个回复
SO网友:D_P

解决方案是CPT应该\'has_archive\' 设置为\'true\'.

相关推荐

get_post_meta pagination

我有自定义字段,具有多个值的数组$metas = get_post_meta($post->ID, \"$meta_key\", false); foreach ( $metas as $metas ){ echo $metas; } 当然,这将返回一个数组。如何对此分页?例如:www.example.com/post-title/1 将返回meta_value[0]和www.example.com/post-title/2 将