• nadiadsz

    (@nadiadsz)


    Hi i’m trying to paginate the categories from the posts, the idea is that when the user selects for example category “uncategorized” the page display all uncategorized posts with numeric pagination. There is something that i’m missing because i did a lot of code modifications but i always get one of these two results:

    – Selecting a category shows all the posts from all categories, also display pagination but if you click next page shows error 404

    – Selecting a category shows the posts from that category but doesn’t display pagination

    I read the codex, questions, guides but still cant get it to work, i’m very new to WP so it most be some noob miskate, any help is appreciated

    Here is what i have right now:

    Category.php

    <?php get_header();
    
    $pagination = get_query_var('paged');
    query_posts($pagination); 
    
     while (have_posts()) : the_post();
                                        get_template_part("blogmasonry");
                                    endwhile; wp_numeric_pagination(); wp_reset_query();
    
    get_footer(); ?>

    functions.php –> the wp_numeric_pagination

    function wp_numeric_pagination() {
        global $wp_query;
    
        $big = 999999999;
        $tag = '<div class="pagination">' . PHP_EOL;
        $tag .= paginate_links( array(
                'base'              => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                'format'            => '?paged=%#%',
                'current'           => max( 1, get_query_var('paged') ),
                'total'             => $wp_query->max_num_pages,
                'prev_next'         => True,
                'prev_text'         => __('«'),
                'next_text'         => __('»'),
            ) ) . PHP_EOL;
        $tag .= '</div>' . PHP_EOL;
        echo $tag;
    }
Viewing 1 replies (of 1 total)
  • Your query needs to be altered to pass $pagination as the ‘paged’ argument like this (untested):

    $pagination = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    query_posts( "paged=$pagination" );

    It is not clear how you are selecting a Category, but the selected Category also needs to be an argument to the query.

Viewing 1 replies (of 1 total)
  • The topic ‘Pagination in category.php problems’ is closed to new replies.