我正在为一位客户开发一个自定义模板,该客户希望在其网站中能够按月筛选帖子。创建存档后。php页面,并将小部件“归档”放在我的侧边栏中,我能够循环并过滤他想要发布的所有帖子,但实际上每个月的最后一篇帖子都没有加载。基本上每个帖子都会每月过滤一次,但不是最后一篇。这是我的存档页面,其中包含存档简单循环:
<?php get_header(); /** Template Name: Archivio */ ?>
<?php if ( have_posts() ) : the_post(); ?>
<section id="news-eventi">
<div class="container">
<div class="breadcrumb-site">
<div class="breadcrumbs" typeof="BreadcrumbList" vocab="http://schema.org/">
<h5 class="text-uppercase font-weight-light"><?php
if(function_exists(\'bcn_display\')) {
bcn_display();
}
?></h5>
</div>
</div>
<div class="row border-left">
<div class="col-lg-9">
<div class="page-title">
<h1 class="text-uppercase"><?php if ( is_month() ) { echo \'ARCHIVIO NEWS: \' . get_the_date(\'F Y\'); } ?></h1>
</div>
<!-- Start the Loop. -->
<?php if (have_posts() ): while ( have_posts() ) : the_post(); ?>
<div class="newsevent-container">
<div class="row mb-5">
<?php if ( has_post_thumbnail() ) { ?>
<div class="col-md-7">
<div class="newsevent-thumbnail-wrapper">
<div class="thumbnail">
<img src="<?php echo get_the_post_thumbnail_url(); ?>" alt="Immagine di Copertina">
</div>
<div class="date">
<p class="day"><?php echo get_the_date(\'d\'); ?></p>
<hr>
<p class="month"><?php echo get_the_date(\'m\'); ?></p>
</div>
</div>
</div>
<div class="col-md-5">
<div class="newsevent-info-wrapper">
<hr>
<div class="newsevent-title">
<h6><?php the_title(); ?></h6>
</div>
<div class="excerpt">
<p><?php the_excerpt(); ?></p>
</div>
<div class="read-all-newsevent">
<a href="<?php the_permalink(); ?>">Leggi Tutto
<span>
<img src="<?php echo get_template_directory_uri(); ?>/images/icons/icon-link-right.svg">
</span>
</a>
</div>
</div>
</div>
<?php } else { ?>
<div class="col-md-2">
<div class="newsevent-thumbnail-wrapper newsevent-thumbnail-wrapper-no-thumbnail">
<div class="date">
<p class="day"><?php echo get_the_date(\'d\'); ?></p>
<hr>
<p class="month"><?php echo get_the_date(\'m\'); ?></p>
</div>
<div class="grey" style="height: 260px;"></div>
</div>
</div>
<div class="col-md-10">
<div class="newsevent-info-wrapper newsevent-info-wrapper-no-thumbnail">
<hr>
<div class="newsevent-title">
<h6><?php the_title(); ?></h6>
</div>
<div class="excerpt">
<p><?php the_excerpt(); ?></p>
</div>
<div class="read-all-newsevent">
<a href="<?php the_permalink(); ?>">Leggi Tutto
<span>
<img src="<?php echo get_template_directory_uri(); ?>/images/icons/icon-link-right.svg">
</span>
</a>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<div class="col-lg-3">
<div class="sidenav">
<div class="sidenav-news-wrapper">
<div class="sidenav-newsevent sidenav-bando-content">
<?php dynamic_sidebar( \'Ultime News Sidebar\' ); ?>
</div>
</div>
<div class="sidenav-newsletter">
<h5>NEWSLETTER</h5>
<p>Rimani in contatto con noi per ricevere aggiornamenti sulle nostre attività e sui bandi.</p>
<?php echo do_shortcode( \'[contact-form-7 id="246" title="side_newsletter"]\' ); ?>
</div>
</div>
</div>
</div>
</div>
</section>
<?php endif; ?>
<?php get_footer(); ?>
我做错了什么?任何帮助都将受到感谢。
谢谢
最合适的回答,由SO网友:Krzysiek Dróżdż 整理而成
它不显示,因为在(have\\u posts())\'的第一个(第三行)之后调用了“the\\u post()”
此调用使循环移动到第二个立柱。因此,如果之后进行适当的循环,那么第一篇文章已经完成了