简体   繁体   中英

pagination error on category page in wordpress

Pagination not working on category page, the query that i used on category page is below: number of paginate is correct but while I am clicking on that number it redirect to home page where I am wrong please give me solution,

//code below

 $cat_ID = get_query_var('cat');
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
 $article = new WP_Query(array('post_type' => 'post','cat' => cat_ID,                  
 'posts_per_page' => '2', 'paged' => $paged));
 while ($article->have_posts()) : $article->the_post();
 $post_id = get_the_ID();

// here is my pagination code

$big = 76;
$args = array(
    'base' => str_replace($big, '%#%',  esc_url(get_pagenum_link($big))),
    'format' => '?paged=%#%',
    'total' => $article->max_num_pages,
    'current' => $paged,
    'prev_next' => True,
    'prev_text' => __('Previous'),
    'next_text' => __('Next'),
    'type' => 'list');
echo paginate_links($args);
<?php while (have_posts()):the_post(); ?>
                    <?php
                    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                    $slide = new WP_Query(array('post_type' => 'post', 'posts_per_page' => '12', 'paged' => $paged));
                    if ($slide->have_posts()) : while ($slide->have_posts()) : $slide->the_post();
                            $post_id = get_the_ID();
                         //show contents here

                       $big = 76;
                        $args = array(
                            'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
                            'format' => '?paged=%#%',
                            'total' => $slide->max_num_pages,
                            'current' => $paged,
                            'prev_next' => True,
                            'prev_text' => __('Previous'),
                            'next_text' => __('Next'),
                            'type' => 'list');

// ECHO THE PAGENATION 
                        echo paginate_links($args);

Change 'format' parameter 'paged' to anything else.

echo paginate_links( array(
...
'format' => '?myparam=%#%',

Then access/get it from your url something like this

$page = (get_query_var('myparam')) ? get_query_var('myparam') : 1;

$slide = new WP_Query(array('post_type' => 'post', 'posts_per_page' => '12', 'paged' => $page));
$category_link = get_category_link( $category_id ) . '/%_%';

'base' => $category_link,
'format'  => 'page/%#%',
'total'   => $article->max_num_pages

hello friend i have faced this type of problem before and the solution that i came with was

Go to setting and then go to to reading tab there you can see "Blog pages show at most" option adjust the number according to your need or until the pagination starts working

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM