$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>posts - Error 404 blogpage2|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

posts - Error 404 blogpage2

matteradmin9PV0评论

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();
                                ?>      

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();
                                ?>      
Share Improve this question asked Aug 11, 2018 at 19:55 ArekArek 1 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 – Mark Kaplun Commented Aug 12, 2018 at 6:08
Add a comment  | 

2 Answers 2

Reset to default 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.

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

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far