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:
<!-- MAIN CONTENT -->
<section id="main-container">
<div class="row">
<div class="content">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php
$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; ?>
<?php
$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); ?>
</div>
<?php get_sidebar(); ?>
</div>
</section>
<!-- END MAIN CONTENT -->
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
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 stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0