Category archive bug
-
– WordPress : 4.4.2
– PHP : 5.6
– Template : Neverland
– Website : https://www.lorrainedarts.frHi there,
I have a problem with my category archives : on each page the posts are the same.
For example if you go on https://lorrainedarts.fr/category/actu/expositions/ and click on page 2, you see the same posts as /page/1/. So the posts are the same on all the archive pages…
After hours I don’t find the bug… :/
In addition, on the author archive pages I have error 404 when I click page 2 of some authors. But for others it works correctly… I don’t understand why.
I hope you could help me.
Thanks !
-
I already try to deactivate all the extensions but the bug remains.
I have check your website, yes your website is error in pagination, but have you tried using default theme ? Because we all are using WP 4.4.2 but there’s no error !
Here is the code of the category.php. I don’t understand where is the bug.
<?php get_header(); $post_options = get_post_meta(get_the_ID(), GT3_THEMESHORT . 'post_options', true); $sidebar_position = get_theme_mod('default_sidebar_position'); $posts_in_row = 2; $posts_in_row_span = 6; ?> <div class="container content <?php echo $sidebar_position; ?>"> <div class="row"> <div class="content_block page_titles <?php echo(($sidebar_position == 'right_sidebar' || $sidebar_position == 'left_sidebar') ? 'span9' : 'span12'); ?>"> <?php $cats = wp_get_post_categories($post->ID); $args = array( 'posts_per_page' => ((isset($post_options['posts_count']) && $post_options['posts_count']) ? $post_options['posts_count'] : '6'), 'category__and' => $cats ); $wp_query2 = new WP_Query(); $wp_query2->query($args); $posti = 1; $posti_all = 1; echo '<div class="posts_container clearfix">'; while ($wp_query2->have_posts()) { $wp_query2->the_post(); if ($posti == 1 && $show_style_class !== 'masonry_style') { echo '<div class="row">'; } echo '<div class="help_class span' . $posts_in_row_span . '">'; if ($show_style_class == 'masonry_style') { get_template_part('loop-masonry'); } else { get_template_part('loop-grid'); } echo '</div>'; if ($posti >= $posts_in_row && $show_style_class !== 'masonry_style') { echo '</div>'; $posti = 0; } if ($posti !== 0 && $posti_all == $wp_query2->post_count && $show_style_class !== 'masonry_style') { echo '</div>'; } $posti++; $posti_all++; } echo '</div>'; gt3_get_theme_pagination('query2'); ?> </div> <?php get_sidebar('left'); get_sidebar('right'); ?> </div> </div> <?php get_footer();
I just found the bug ! I have to put : ‘paged’ => $paged,
<?php get_header(); $post_options = get_post_meta(get_the_ID(), GT3_THEMESHORT . 'post_options', true); $sidebar_position = get_theme_mod('default_sidebar_position'); $posts_in_row = 2; $posts_in_row_span = 6; ?> <div class="container content <?php echo $sidebar_position; ?>"> <div class="row"> <div class="content_block page_titles <?php echo(($sidebar_position == 'right_sidebar' || $sidebar_position == 'left_sidebar') ? 'span9' : 'span12'); ?>"> <?php $cats = wp_get_post_categories($post->ID); $args = array( 'posts_per_page' => ((isset($post_options['posts_count']) && $post_options['posts_count']) ? $post_options['posts_count'] : '6'), 'paged' => $paged, 'post_status' => 'publish', 'category__and' => $cats ); $wp_query2 = new WP_Query(); $wp_query2->query($args); $posti = 1; $posti_all = 1; echo '<div class="posts_container clearfix">'; while ($wp_query2->have_posts()) { $wp_query2->the_post(); if ($posti == 1 && $show_style_class !== 'masonry_style') { echo '<div class="row">'; } echo '<div class="help_class span' . $posts_in_row_span . '">'; if ($show_style_class == 'masonry_style') { get_template_part('loop-masonry'); } else { get_template_part('loop-grid'); } echo '</div>'; if ($posti >= $posts_in_row && $show_style_class !== 'masonry_style') { echo '</div>'; $posti = 0; } if ($posti !== 0 && $posti_all == $wp_query2->post_count && $show_style_class !== 'masonry_style') { echo '</div>'; } $posti++; $posti_all++; } echo '</div>'; gt3_get_theme_pagination('query2'); ?> </div> <?php get_sidebar('left'); get_sidebar('right'); ?> </div> </div> <?php get_footer();
But I already have the bug in the author’s pages.
For some authors it works correctly but for others I have an error 404 when I click on the page 2This is the code
<?php get_header(); $post_options = get_post_meta(get_the_ID(), GT3_THEMESHORT . 'post_options', true); $sidebar_position = get_theme_mod('default_sidebar_position'); if (isset($post_options['posts_in_a_row']) && $post_options['posts_in_a_row'] == 3) { $posts_in_row = 3; $posts_in_row_span = 4; } elseif (isset($post_options['posts_in_a_row']) && $post_options['posts_in_a_row'] == 1) { $posts_in_row = 1; $posts_in_row_span = 12; } else { $posts_in_row = 2; $posts_in_row_span = 6; } $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); ?> <div class="container content <?php echo $sidebar_position; ?>"> <div class="row"> <div class="content_block page_titles <?php echo(($sidebar_position == 'right_sidebar' || $sidebar_position == 'left_sidebar') ? 'span9' : 'span12'); ?>"> <h1>à propos de l'auteur</h1> <?php if ( function_exists( 'wpsabox_author_box' ) ) echo wpsabox_author_box(); ?> <h1>Ses dernières contributions</h1> <br/> <?php $args = array( 'posts_per_page' => ((isset($post_options['posts_count']) && $post_options['posts_count']) ? $post_options['posts_count'] : '6'), 'post_type' => 'post', 'paged' => $paged, 'post_status' => 'publish', 'author' => $curauth->ID ); $wp_query2 = new WP_Query(); $wp_query2->query($args); $posti = 1; $posti_all = 1; echo '<div class="posts_container clearfix">'; while ($wp_query2->have_posts()) { $wp_query2->the_post(); if ($posti == 1 && $show_style_class !== 'masonry_style') { echo '<div class="row">'; } echo '<div class="help_class span' . $posts_in_row_span . '">'; if ($show_style_class == 'masonry_style') { get_template_part('loop-masonry'); } else { get_template_part('loop-grid'); } echo '</div>'; if ($posti >= $posts_in_row && $show_style_class !== 'masonry_style') { echo '</div>'; $posti = 0; } if ($posti !== 0 && $posti_all == $wp_query2->post_count && $show_style_class !== 'masonry_style') { echo '</div>'; } $posti++; $posti_all++; } echo '</div>'; gt3_get_theme_pagination('query2'); ?> </div> <?php get_sidebar('left'); get_sidebar('right'); ?> </div> </div> <?php get_footer();
I found more explanations.
The author page displays 6 articles per page.
In fact, the 404 error page appears on author’s page 2 when the author has less than 20 articles.
For an author who have 23 articles the 404 error page appears on page 3
For an author who have 469 articles, the 404 error page appears on page 26
…So it’s like the bug depends of the number of articles, it’s really strange… It’s like the number of pages isn’t well calculated to display all the articles.
Hope someone can help me ??
I just found the problem thanks to : https://wordpress.stackexchange.com/questions/176347/pagination-returns-404-after-page-20
In fact I just have to set posts per page to 6 in admin (it was 20).
- The topic ‘Category archive bug’ is closed to new replies.