admin管理员组文章数量:1429841
I'm trying to build a post gallery page with pagination. Posts and pagination are displayed fine but for some reason pagination won't show the clicked page and remain on page 1. This is my code:
<?php /* My Template: Gallery Page */ ?>
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<div id="gridcontainer">
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'author' => 1,
'post_per_page' => 8,
'paged' => $paged,
);
$the_query = new WP_Query( $args );
global $wp_query;
$tmp_query = $wp_query;
$wp_query = null;
$wp_query = $the_query;
if ($the_query->have_posts()) :
while ($the_query->have_posts()) : $the_query->the_post();
?>
<div class="griditem">
<div class="postimage">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumbnail'); ?></a>
</div>
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
</div>
<?php
endwhile;
the_posts_pagination( array( 'mid_size' => 2 ) );
wp_reset_postdata();
else :
// no post found code
endif;
$wp_query = null;
$wp_query = $tmp_query;
?>
</div>
</main>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Also I was using query_posts before but apparently that isn't good anymore. Is the code I'm using now up to date and problem-free besides the malfunctioning pagination?
本文标签: wp queryPagination Shows Up But Won39t Work on Custom Gallery Page
版权声明:本文标题:wp query - Pagination Shows Up But Won't Work on Custom Gallery Page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745547586a2662778.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论