Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pagination link is not working /page/2 - NOT FOUND - Wordpress

I need to create a paginator in my blog page, until this its good, but when i click in a link of my pagination i got NOT FOUND page, i need to know if i need to able something in the panel to wordpress able the access to ?page=N

function:

    function get_pagination($the_query) {
    global $paged;
    $total_pages = $the_query->max_num_pages;
    $big = 999999999;

    if ($total_pages > 1) {
        ob_start();

        echo paginate_links( array(
            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format' => '/page/%#%',
            'current' => $paged,
            'total' => $total_pages,
            'prev_text' => '',
            'next_text' => ''
        ));
        return ob_get_clean();
    }
    return null;
}

my blog code

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
        // echo $paged;
        $produtos = new WP_Query(array(
            'post_type'      => 'blog',
            'posts_per_page' => 1,
            'orderby'        => 'date',
            'order'          => 'asc',
            'paged'          => $paged,
            'tax_query'      => array(
                array(
                    'taxonomy' => 'categorias',
                    'field'    => 'slug',
                    'terms'    => ACTIVE
                )
            )
        ));

        while ( $produtos->have_posts() ) : $produtos->the_post();

        //CONTENT

        endwhile;

        echo get_pagination($produtos);
like image 638
gabrielbuzzi Avatar asked Sep 11 '13 14:09

gabrielbuzzi


People also ask

How do I enable pagination in WordPress?

Pagination is actually baked right into WordPress. To set everything up, you'll need to visit the WordPress admin first. From there, you can visit Settings -> Reading. This is where you can set up the basic formatting of your posts.

How do I change my pagination link in WordPress?

First add the following to functions. php . This function will rewrite our base pagination prefix to and empty string. Second we add the our paginate_links() function to our archives page.

How do I get pagination page numbers in WordPress?

Since WP 3.9. 0, $paged = get_query_var( 'paged', $default ) allows a second argument with the default value. So, $paged = get_query_var( 'paged', 1 ) or $paged = get_query_var( 'paged', 0 ) (as @Kip noticed) will do.


3 Answers

Go to admin Dashboard then Settings->Reading then set Blog pages show at most is equal to you query posts_per_page. So in your query if you set posts_per_page => 2 then Blog pages show at mostwill be 2

like image 78
Md Nozibulla Bashar Avatar answered Oct 06 '22 12:10

Md Nozibulla Bashar


This is what I found and resolved the issue I had!

[...] I needed to go into the wp-admin page (the wordpress dashboard) and go to Settings then Reading and in the "Blog pages show at most" field I changed the value from '10' to '6' (the number of posts I indicated in $wp_query->query('showposts=6&cat=1'.'&paged='.$paged);)

like image 26
user2958620 Avatar answered Oct 06 '22 11:10

user2958620


use following paged query

if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }

    $produtos = new WP_Query(array(
            'post_type'      => 'blog',
            'posts_per_page' => -1,
            'orderby'        => 'date',
            'order'          => 'asc',
            'paged'          => $paged,
            'tax_query'      => array(
                array(
                    'taxonomy' => 'categorias',
                    'field'    => 'slug',
                    'terms'    => ACTIVE
                )
            )
        ));

        while ( $produtos->have_posts() ) : $produtos->the_post();

        //CONTENT

        endwhile;

        echo get_pagination($produtos);
like image 44
Jothi Kannan Avatar answered Oct 06 '22 12:10

Jothi Kannan