Wordpress分页url第一页


wordpress pagination url first page

我在我的网站上使用paginate_links

当我点击第二个url更改为mywebsite.com /page/2。然后我圈页码1和网站url显示mywebsite.com /page/1。我想删除/page/1在首页第一页。

本期仅限首页。分类页面工作正常

Ex: <<prev | 1 | 2 | next >>

有人能帮我吗?

paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '/page/%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages,
        'prev_next' => true,
        'prev_text'    => __('Prev Page'),
        'next_text'    => __('Next Page'),
        'type'  => 'array'
    ) );

这个需求有一个过滤器

add_filter( 'paginate_links', function($link){
    //Remove link page/1/ from the first element and prev element
    
    if(is_paged()){
        $link= str_replace('page/1/', '', $link);
    }
    return $link;
} );

如果yoursite.com/page/1和yoursite.com是相同的,为什么不使用jquery来改变你的分页链接的href属性?

$(".pagination a:first").attr("href", "http://example.com/");

这段代码只是改变了分页的第一个链接的url。

编辑:这将改变你的网站的prev链接的href属性。如果user在第3页,或者其他地方,那就不好了。

试试这个:

if($('.pagination a:first').attr('href') === "http://example.com/page/1") {
    // this is page 2.
    $(".pagination a:first").attr("href", "http://example.com/");
}
    $(".pagination a:nth-child(2)").attr("href", "http://example.com/");

小提琴