简体   繁体   中英

Custom Archive page doesn't work with dates or tags but works with categories

I have customized the archive page for a client, and have edited the query that it makes to exclude a category and limit the page to 8 posts. I've also added a sidebar which uses the Archive widget. Whenever I click on an Archive link it will show all of the posts not the posts for that Month. The same thing happens with the tags, it will return all the posts and not just the posts with that tag.

<div class="row site-module-inner">

            <?php $args = array( 'posts_per_page' => 8,
                                 'category__not_in' => get_category_by_slug('news')->term_id,); ?>); ?>
            <?php $query = new WP_Query($args); ?>
            <?php $count = $query->post_count;
                  $counter = $query->post_count;
                  if ($count % 2 == 0) {
                    $last = true;
                  } else {
                    $last = false;
                  }
                  ?>
            <?php while ( $query->have_posts() ) : $query->the_post(); ?>

                        <div class="item <?php if ((!($last) && $counter == 1) || ($last && $counter <= 2)) { echo " bottom"; } ?> ">

                            <?php get_template_part( 'template-parts/post', 'listing' ); ?>

                        </div> <!-- item -->
              <?php $counter--; ?>
          <?php endwhile; wp_reset_query();?>

  </div> <!-- row -->

What I've provided is the query loop for the archive page, on the page there are no other query loops except for a pagination loop, but it doesn't affect the main loop, I have tested for that. Any suggestions or insight is appreciated

使用wp_reset_postdata ,而不是wp_reset_query()。

I have found the solution to my own problem, a custom query completely overrides any arguments from the original query. Which is why it won't work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM