admin管理员组文章数量:1336660
I'm using this code to display page pagination on my website. But when I click to go to the second page it shows me "Page not found" error.
Does someone know what is wrong with my code that is not displaying the posts on the second page?
<?php
$currCat = get_category(get_query_var('cat'));
$cat_name = $currCat->name;
$cat_id = get_cat_ID( $cat_name );
?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query-
>query('showposts=3&post_type=post&paged='.$paged.'&cat='.$cat_id);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<div class="module-container">;
<div class="content">;
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title();
?></a>
</div>
</div>
<?php endwhile; ?>
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo '<div class="paginate-links">';
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big )
) ),
'format' => '?paged=%#%',
'prev_text' => __('<<'),
'next_text' => __('>>'),
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
echo '</div>';
?>
I'm using this code to display page pagination on my website. But when I click to go to the second page it shows me "Page not found" error.
Does someone know what is wrong with my code that is not displaying the posts on the second page?
<?php
$currCat = get_category(get_query_var('cat'));
$cat_name = $currCat->name;
$cat_id = get_cat_ID( $cat_name );
?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query-
>query('showposts=3&post_type=post&paged='.$paged.'&cat='.$cat_id);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<div class="module-container">;
<div class="content">;
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title();
?></a>
</div>
</div>
<?php endwhile; ?>
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo '<div class="paginate-links">';
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big )
) ),
'format' => '?paged=%#%',
'prev_text' => __('<<'),
'next_text' => __('>>'),
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
echo '</div>';
?>
Share
Improve this question
asked Mar 26, 2018 at 1:19
user3507500user3507500
134 bronze badges
5
|
1 Answer
Reset to default -2Just set the permalink to numeric ( Under Setting -> Permalinks ). This works for me.
本文标签: postsPage not found after clicking on pagination
版权声明:本文标题:posts - Page not found after clicking on pagination 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742418324a2471152.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
pre_get_posts
rather than create a new query. – Milo Commented Mar 26, 2018 at 1:25