【问题标题】:Wordpress author page pagination per post type每个帖子类型的 Wordpress 作者页面分页
【发布时间】:2019-01-24 11:04:14
【问题描述】:

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

我尝试为自定义帖子添加分页,但它重定向到多站点主页。是 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 wordpress pagination


【解决方案1】:

您必须将以下代码添加到您的活动主题的 function.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');

经过测试并运行良好

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多