paginate_links'base'和'format'无法正常工作

时间:2018-04-18 02:40:25

标签: php ajax wordpress pagination

我正在使用paginate_links()来显示ajax调用的分页。

这是我的代码

<?php 
    $big = 999999999; // need an unlikely integer       
    $pagination = paginate_links(array(
        'mid_size'  => 2,
        'prev_text' =>esc_html__('Previous', 'travel-tour'),
        'next_text' => esc_html__('Next', 'travel-tour'),
        'current' => max( 1, get_query_var('paged') ),
        'total' => $cat_query->max_num_pages,
        'type' => 'array',
        'base'      => '%_%',
        'format'    => '/paged/%#%',

    ) );
    echo '<li>' . implode( '</li><li>', $pagination ) . '</li>';
?>

当我尝试更改'格式'=&gt; '?paged /%#%'用?字符然后它工作,网址显示如下(//localhost/mysite.com/video/packages/?paged/2)

但当我将其更改为'format'=&gt; '/ paged /%#%'与/字符然后它显示如下// localhost / paged / 2

我需要它看起来没有这个?字符 //localhost/mysite.com/video/packages/paged/2

希望这是有道理的,谢谢

这是我的完整代码

<?php
add_action( 'wp_ajax_nopriv_load-filter', 'prefix_load_cat_posts' );
add_action( 'wp_ajax_load-filter', 'prefix_load_cat_posts' );

function prefix_load_cat_posts () {
    global $post,  $wp_query, $wp_rewrite;

    $cat_id = $_POST[ 'cat' ];

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

    $args = array (
        'cat' => $cat_id,
        'posts_per_page' => 6,
        'order' => 'DESC',
        'paged' => $paged
    );

    $cat_query = new WP_Query($args);

    if($cat_query->have_posts()) :
        while($cat_query->have_posts()) : $cat_query->the_post();
            get_template_part( 'template-parts/content', get_post_format() );
        endwhile;
        wp_reset_query();
?>
    <div class="page-nation">
        <ul class="pagination pagination-large">
        <?php 
            $big = 999999999; // need an unlikely integer       
            $pagination = paginate_links(array(
                'mid_size'  => 2,
                'prev_text' =>esc_html__('Previous', 'travel-tour'),
                'next_text' => esc_html__('Next', 'travel-tour'),
                'current' => max( 1, get_query_var('paged') ),
                'total' => $cat_query->max_num_pages,
                'type' => 'array',
                'base'      => '%_%',
                'format'    => '?paged/%#%',

            ) );
            echo '<li>' . implode( '</li><li>', $pagination ) . '</li>';
        ?>
        </ul>
    </div> 
<?php
    endif;

} 

0 个答案:

没有答案
相关问题