-1

Hello i have problem.

I can't view /blog/page/2/ i klick "_posts_link" and error 404 shows me

Blog Page -> home.php

                <?php 
                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                $args = array('posts_per_page' => 5, 'paged' => $currentPage);
                query_posts($args);
                if( have_posts() ): $i = 0;

                    while( have_posts() ): the_post(); ?>

                                <?php $i++; endwhile; ?>
                                <ul class="uk-pagination uk-background-primary uk-light">
                                    <li><?php next_posts_link('<span class="uk-margin-small-right" uk-pagination-previous></span> Stare Posty'); ?></li>
                                    <li class="uk-margin-auto-left"><?php previous_posts_link('Nowe posty <span class="uk-margin-small-left" uk-pagination-next>'); ?></li>
                                </ul>

                                <?php endif;
                                    wp_reset_query();
                                ?>      
1
  • once you use query_posts there is no point in asking about pagination, just never use it ever. In any case the code you should is unlikely to be the reason you get 404 Commented Aug 12, 2018 at 6:08

2 Answers 2

0

I guess you don't need to target a taxonomy. You can use the code below:

function query_change_function( $query ) {
     $query->set( 'posts_per_page', 5 );
}
add_action('pre_get_posts', 'query_change_function');

You should wrap the $query->set( 'posts_per_page', 5 ); around with if ( ! is_admin() && is_home() ) {//the $query->set code} to avoid it changing to 5-posts everywhere.

-1

Use this for pagination

<?php
$paged = ( get_query_var( 'page' ) ) ? absint( get_query_var( 'page' ) ) : 1;
$content_args=array(
         'post_type' => 'post',
         'orderby' => 'meta_value_num',
         'paged' => $paged,
         'posts_per_page' => '5',
     );
    $wp_query = new WP_Query($content_args);
    while ($wp_query->have_posts()): $wp_query->the_post();?>

    //content here

   <?php endwhile;?>

Pagination

<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo 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
) );?>
1
  • A wall of code is not a good answer. Answers should educate to help people avoid repeating the same mistakes, and a wall of code which contains zero comments and no real explanation as to "why" is almost worthless. Commented Aug 12, 2018 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.