自定义帖子类型,自定义分类法在分页时出现404错误

时间:2019-03-25 23:08:32

标签: wordpress pagination wordpress-theming custom-post-type

页码和按钮显示在自定义帖子类型档案库和自定义分类法档案中,但呈现404。

我在做什么错了?

以下是自定义帖子类型档案的查询:

<?php $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; $exec_query = new WP_Query( array (
    'post_type'         => 'tracker',
    'publish_status'    => 'publish',
    'posts_per_page'    => 6,
    'paged'             => $paged,
) );
}

if ( $exec_query->have_posts() ) { ?><?php global $wp_query; $posts_per_page = $wp_query->query["posts_per_page"]; $posts_found = $wp_query->found_posts; ?><?php while ( $exec_query->have_posts() ): $exec_query->the_post(); ?>

这是我用于自定义帖子类型档案的分页代码:

 <section class="pagination">
    <?php global $exec_query;

        $big = 999999999;
        $translated = __( 'Page', 'theme-name' );
        echo paginate_links( array(
            'base'  => str_replace( $big, '%#%', esc_url (get_pagenum_link( $big )) ),
            'format'                => 'page/%#%/',
            'current'               => max( 1, get_query_var('paged') ),
            'prev_text'         => __('« Previous'),
            'next_text'         => __('Next »', $exec_query->max_num_pages),
            'total'                 => $exec_query->max_num_pages,
            'before_page_number'    => '<span class="screen-reader-text">'.$translated.'</span> '
    ) );
    ?>
</section>

以下是自定义分类法之一的查询:

<?php $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; $post_type = get_queried_object(); echo $post_type->rewrite['slug']; $loop = new WP_Query( array(

    'post_type' => 'tracker',
    'posts_per_page' => 6,
    'paged' => $paged,
                'tax_query'         => array(
                    array(
                        'taxonomy'  => 'taxonomy1',
                        'field'     => 'slug',
                        'terms'     => $post_type,
                    ),
                ),
) ); if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); ?>

这是一种分类法的分页代码:

<section class="pagination">
    <?php global $loop;

        $big = 999999999;
        $translated = __( 'Page', 'theme-name' );
        echo paginate_links( array(
            'base'  => str_replace( $big, '%#%', esc_url (get_pagenum_link( $big )) ),
            'format'                => 'page/%#%/',
            'current'               => max( 1, get_query_var('paged') ),
            'prev_text'         => __('« Previous'),
            'next_text'         => __('Next »', $loop->max_num_pages),
            'total'                 => $loop->max_num_pages,
            'before_page_number'    => '<span class="screen-reader-text">'.$translated.'</span> '
    ) );
    ?>
</section>

0 个答案:

没有答案