wordpress分页广告额外斜线到网址

时间:2017-07-05 14:54:53

标签: wordpress

使用自定义帖子类型我似乎无法使分页正常工作。一切正常,但是当我点击下一页时,网址会在网址中得到一个额外的斜线,不知道为什么会发生这种情况,但是当使用分页时,每次都会在网址上添加一个新的斜杠。

// out

site.com/projects/ ,  
site.com/projects//page/2,  
site.com/projects///page/3,  
site.com/projects////page/4 

...and so on.

//使用的代码

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    $query = new WP_Query( array( 
        'post_type'      => 'projects', 
        'posts_per_page' => 5,
        'paged'          => $paged

    ) );


    if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();

       the_title();

    endwhile; 

        $total_pages = $query->max_num_pages;

        if ($total_pages > 1){

            $current_page = max(1, get_query_var('paged'));

            echo paginate_links(array(
                'base'      => get_pagenum_link(1) . '%_%',
                'format'    => '/page/%#%',
                'current'   => $current_page,
                'total'     => $total_pages,
                'prev_text' =>  esc_html__('volgende »', 'infrafocus'),
                'next_text' =>  esc_html__('« vorige' , 'infrafocus'),
            ));
        }

    }

    wp_reset_postdata();

    endif;

3 个答案:

答案 0 :(得分:2)

有时在自定义帖子类型分页的情况下,您必须在function.php中添加重写规则 添加功能如:

function custom_rewrite_basic() {
  add_rewrite_rule('^leaf/([0-9]+)/?', 'index.php/projects?page=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_basic');

请参阅此链接以获取更多信息:https://codex.wordpress.org/Rewrite_API/add_rewrite_rule

答案 1 :(得分:1)

尝试将'format' => '/page/%#%',更改为'format' => 'page/%#%',

答案 2 :(得分:0)

用户格式如下

'format'             => '?paged=%#%'

https://codex.wordpress.org/Function_Reference/paginate_links