按帖子类型划分的 WordPress 作者页面分页



我有一个作者页面,我在其中显示作者帖子和作者自定义帖子。

我试图为自定义帖子添加分页,但它重定向到多站点主页。是nginx配置/站点设置或我的代码有问题吗?

来源: https://sochi.asp.sale/author/svetlanapolyakova/

我使用此分页代码:

<div class="pagination">
    <?php 
    $url = 'https://' . $_SERVER['SERVER_NAME'];
    $author = get_the_author_meta('user_nicename', $curauth->ID);
        echo paginate_links( array(
            'base'         => $url . '/author/%_%',
            'total'        => $wp_query->max_num_pages,
            'current'      => max( 1, get_query_var( 'paged' ) ),
            'format'       => $author . '/?paged=%#%',
            'show_all'     => false,
            'type'         => 'plain',
            'end_size'     => 2,
            'mid_size'     => 1,
            'prev_next'    => true,
            'prev_text'    => sprintf( '<i></i> %1$s', __( 'Новее', 'text-domain' ) ),
            'next_text'    => sprintf( '%1$s <i></i>', __( 'Старее', 'text-domain' ) ),
            'add_args'     => false,
            'add_fragment' => '',
        ) );
    ?>
</div>  
您必须将

以下代码添加到您的函数中.php您的活动主题

function custom_type_archive_display($query) {
    if (is_post_type_archive('custom_post_type')) {
        $query->set('posts_per_page',1); //Here add number of posts you want to display per page
        return;
    }
}
add_action('pre_get_posts', 'custom_type_archive_display');

经过测试,运行良好

最新更新