Problem: ( kriesi ) pagination doesn’t work in homepage

The question:

When I set this template as homepage, pagination doesn’t work.
I see the buttons, but when I click the button for page 2, nothing happens, doesn’t go on page 2, it still remain in page 1.

What is wrong? Where is the mistake?
I read all posts from here & from internet about this issue, but nothing works.

Solution for pagination is this: kriesi.

Here is the code:

<section id="main-container">
    <div class="row">
        <div class="content">

            <?php if (have_posts()) : while (have_posts()) : the_post();?>

            $template_name =   get_post_meta( $wp_query->post->ID, '_wp_page_template', true );
            $post_type =  str_replace( array('template-', '.php'), array(''), $template_name);

            <?php the_content(); ?>

            <?php endwhile; endif; ?>
            $loop = new WP_Query("post_type=$post_type&paged=$paged");
            if ($loop->have_posts()) : while ($loop->have_posts()) : $loop->the_post(); ?>

             <?php get_template_part('loop', $post_type) ?>

                                       <?php endwhile; ?> 
                                       <?php else: ?>
                <?php require THEME_DIR.'/empty.php'; ?>
                                       <?php endif; ?>

                                       <?php pagination($loop->max_num_pages); ?>

        <?php get_sidebar(); ?>

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

You probably don’t set the $paged variable correctly. Try to rewrite your code like this:

$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$loop = new WP_Query( "post_type=$post_type&paged=$paged" );

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment