doula4096 2018-04-18 02:40
浏览 55

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

I am using paginate_links() to display the pagination from an ajax call.

This is my code

<?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>';
?>

When I try to change the 'format' => '?paged/%#%' with the ? character then it works, the url is shown like this (//localhost/mysite.com/video/packages/?paged/2)

but when I change it to 'format' => '/paged/%#%' with the / character then it shows like this //localhost/paged/2

I need it to look like this without the ? character //localhost/mysite.com/video/packages/paged/2

Hope this makes sense, thanks

This is the complete code that I have

<?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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行