【问题标题】:Custom Post Type Pagination return 404自定义帖子类型分页返回 404
【发布时间】:2019-02-05 17:06:05
【问题描述】:

我正在尝试在我的 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 插件,我只需要它来完成它。

非常感谢!

【问题讨论】:

    标签: wordpress plugins pagination


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-22
      • 1970-01-01
      • 2014-09-29
      • 2014-07-12
      • 1970-01-01
      • 2015-06-07
      • 2014-05-20
      • 2012-01-06
      相关资源
      最近更新 更多