admin管理员组文章数量:1022553
I am using pagination in wordpress, the truth is that I have used it several times. But this time, when I access page number 2, I get an error 404. I've searched a bit and I've tried several functions, but not work. Here I leave my loop
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$news = array(
'post_type' => 'post',
'category_name' => 'projekte',
'order' => 'DESC',
'paged' => $paged,
'posts_per_page' => 8
);
$wp_query = new WP_Query($news);
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<div class="column is-one-quarter">
<a href="<?php the_permalink() ?>">
<div class="thecontent">
<div class="image-container">
<?php the_post_thumbnail(); ?>
</div>
<div class="post-container">
<div class="subtitle">
<?php the_title(); ?>
</div>
<div class="contain">
<p><?php the_field('beschreibung'); ?></p>
</div>
</div>
</div>
</a>
</div>
<?php endwhile; ?>
<div class="pagination">
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages,
'show_all' => true,
'end_size' => 1,
'mid_size' => 2,
'prev_next' => true,
'prev_text' => __(''),
'next_text' => __(''),
'type' => 'plain',
'add_args' => false,
'add_fragment' => '',
'before_page_number' => '',
'after_page_number' => ''
));
?>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
I hope someone can help me, because I'm under pressure and I feel blocked. Thanks.
I am using pagination in wordpress, the truth is that I have used it several times. But this time, when I access page number 2, I get an error 404. I've searched a bit and I've tried several functions, but not work. Here I leave my loop
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$news = array(
'post_type' => 'post',
'category_name' => 'projekte',
'order' => 'DESC',
'paged' => $paged,
'posts_per_page' => 8
);
$wp_query = new WP_Query($news);
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<div class="column is-one-quarter">
<a href="<?php the_permalink() ?>">
<div class="thecontent">
<div class="image-container">
<?php the_post_thumbnail(); ?>
</div>
<div class="post-container">
<div class="subtitle">
<?php the_title(); ?>
</div>
<div class="contain">
<p><?php the_field('beschreibung'); ?></p>
</div>
</div>
</div>
</a>
</div>
<?php endwhile; ?>
<div class="pagination">
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages,
'show_all' => true,
'end_size' => 1,
'mid_size' => 2,
'prev_next' => true,
'prev_text' => __(''),
'next_text' => __(''),
'type' => 'plain',
'add_args' => false,
'add_fragment' => '',
'before_page_number' => '',
'after_page_number' => ''
));
?>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
I hope someone can help me, because I'm under pressure and I feel blocked. Thanks.
Share Improve this question edited May 16, 2019 at 12:23 Dario B. asked May 16, 2019 at 10:20 Dario B.Dario B. 15510 bronze badges 4 |1 Answer
Reset to default 0I found the solution.
First, in functions.php:
function mg_news_pagination_rewrite() {
add_rewrite_rule(get_option('category_base').'/page/?([0-9]{1,})/?$', 'index.php?
pagename='.get_option('category_base').'&paged=$matches[1]', 'top');
}
add_action('init', 'mg_news_pagination_rewrite');
and then in wordpress, settings> Permalinks changes must be saved
I am using pagination in wordpress, the truth is that I have used it several times. But this time, when I access page number 2, I get an error 404. I've searched a bit and I've tried several functions, but not work. Here I leave my loop
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$news = array(
'post_type' => 'post',
'category_name' => 'projekte',
'order' => 'DESC',
'paged' => $paged,
'posts_per_page' => 8
);
$wp_query = new WP_Query($news);
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<div class="column is-one-quarter">
<a href="<?php the_permalink() ?>">
<div class="thecontent">
<div class="image-container">
<?php the_post_thumbnail(); ?>
</div>
<div class="post-container">
<div class="subtitle">
<?php the_title(); ?>
</div>
<div class="contain">
<p><?php the_field('beschreibung'); ?></p>
</div>
</div>
</div>
</a>
</div>
<?php endwhile; ?>
<div class="pagination">
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages,
'show_all' => true,
'end_size' => 1,
'mid_size' => 2,
'prev_next' => true,
'prev_text' => __(''),
'next_text' => __(''),
'type' => 'plain',
'add_args' => false,
'add_fragment' => '',
'before_page_number' => '',
'after_page_number' => ''
));
?>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
I hope someone can help me, because I'm under pressure and I feel blocked. Thanks.
I am using pagination in wordpress, the truth is that I have used it several times. But this time, when I access page number 2, I get an error 404. I've searched a bit and I've tried several functions, but not work. Here I leave my loop
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$news = array(
'post_type' => 'post',
'category_name' => 'projekte',
'order' => 'DESC',
'paged' => $paged,
'posts_per_page' => 8
);
$wp_query = new WP_Query($news);
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<div class="column is-one-quarter">
<a href="<?php the_permalink() ?>">
<div class="thecontent">
<div class="image-container">
<?php the_post_thumbnail(); ?>
</div>
<div class="post-container">
<div class="subtitle">
<?php the_title(); ?>
</div>
<div class="contain">
<p><?php the_field('beschreibung'); ?></p>
</div>
</div>
</div>
</a>
</div>
<?php endwhile; ?>
<div class="pagination">
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages,
'show_all' => true,
'end_size' => 1,
'mid_size' => 2,
'prev_next' => true,
'prev_text' => __(''),
'next_text' => __(''),
'type' => 'plain',
'add_args' => false,
'add_fragment' => '',
'before_page_number' => '',
'after_page_number' => ''
));
?>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
I hope someone can help me, because I'm under pressure and I feel blocked. Thanks.
Share Improve this question edited May 16, 2019 at 12:23 Dario B. asked May 16, 2019 at 10:20 Dario B.Dario B. 15510 bronze badges 4- Have you tried saving your permalinks. Please go to Settings > Permalinks in WP Admin and click Save Changes – Sneha Agarwal Commented May 16, 2019 at 11:42
- Possible duplicate of WordPress /page/2 404 pagination problem - what to do? – norman.lol Commented May 16, 2019 at 12:08
-
Here's a good read as well: stackoverflow/questions/42189247/…. On what page or post exactly are you displaying the results of your custom query? You may need to adjust the main query via
pre_get_posts
, so that WordPress globally knows aha oho what query exactly is running on that page right now, will it have pages or should I trigger a 404 as not every page should simply be accessible with a*/page/*
URL. – norman.lol Commented May 16, 2019 at 12:10 - I've tried it before, it does not give me any solution. – Dario B. Commented May 16, 2019 at 12:24
1 Answer
Reset to default 0I found the solution.
First, in functions.php:
function mg_news_pagination_rewrite() {
add_rewrite_rule(get_option('category_base').'/page/?([0-9]{1,})/?$', 'index.php?
pagename='.get_option('category_base').'&paged=$matches[1]', 'top');
}
add_action('init', 'mg_news_pagination_rewrite');
and then in wordpress, settings> Permalinks changes must be saved
本文标签: phpPagination 404 error(I have refreshed the permalinks and tried several previous options)
版权声明:本文标题:php - Pagination 404 error(I have refreshed the permalinks and tried several previous options) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745484968a2152700.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
pre_get_posts
, so that WordPress globally knows aha oho what query exactly is running on that page right now, will it have pages or should I trigger a 404 as not every page should simply be accessible with a*/page/*
URL. – norman.lol Commented May 16, 2019 at 12:10