これは私の WordPress ループです。私はいくつかのことを試しましたが、思い通りに機能するものはありません。
while ( $loop->have_posts() ) : $loop->the_post();
$timestamp = get_post_meta( $post->ID, '_tatort_datum', true );
$ts_jahr = strftime("%Y",$timestamp);
if($ts_jahr != $jahr_l) {
echo '<h2 class="spacer_jahr" id="'. $ts_jahr .'">'. $ts_jahr .'</h2>';
}
$jahr_l = $ts_jahr;
$ts_monat = strftime("%m",$timestamp);
if($ts_monat != $monat_l) {
echo '<h3 class="spacer_monat" id="'. strtolower($monat[$ts_monat]) . "_" . $ts_jahr. '">'. $monat[$ts_monat] .'</h3>';
}
$monat_l = $ts_monat;
<article>here the content</article>
<?php endwhile; wp_reset_query(); ?>
出力は次のとおりです。
<h2>Headline</h2>
<h3>Headline</h3>
<article>Content</article>
<article>Content</article>
<article>Content</article>
<h3>Headline</h3>
<article>Content</article>
<article>Content</article>
しかし、私はこの出力が必要です:
<h2>Headline</h2>
<div class="month"> /* Here is the Change */
<h3>Headline</h3>
<article>Content</article>
<article>Content</article>
<article>Content</article>
<div>
<div class="month">
<h3>Headline</h3>
<article>Content</article>
</div>
しかし、私は今、これを行う方法がわかりません。div
毎月新しい記事のコンテナーが必要なので、正しい方法を説明するヒントまたはコード スニペットが必要です。