Php WordPress循环分组div
这是我的WordPress循环。我尝试了一些东西,但没有一件像我想要的那样有效Php WordPress循环分组div,php,wordpress,if-statement,Php,Wordpress,If Statement,这是我的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
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(); ?>
while($loop->have_posts()):$loop->the_post();
$timestamp=get_post_meta($post->ID,'u tatort_datum',true);
$ts_jahr=strftime(“%Y”,$timestamp);
如果($ts_jahr!=$jahr_l){
回声“.$Tsu jahr.”;
}
$jahr_l=$ts_jahr;
$ts_monat=strftime(“%m”,$timestamp);
如果($ts\u monat!=$monat\u l){
回音“.$monat[$ts_monat]”;
}
$monat_l=$ts_monat;
这里是内容
输出为:
<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
容器,每个月都围绕着新文章,所以我需要一个提示或一个代码片段来解释正确的方法 您可以使用布尔变量$divOpen
跟踪
是否打开。。。
$divOpen=false;
而($loop->have_posts()):$loop->the_post();
$timestamp=get_post_meta($post->ID,'u tatort_datum',true);
$ts_jahr=strftime(“%Y”,$timestamp);
如果($ts_jahr!=$jahr_l){
如果($divOpen){
回声';
$divOpen=false;
}
回声“.$Tsu jahr.”;
}
$jahr_l=$ts_jahr;
$ts_monat=strftime(“%m”,$timestamp);
如果($ts\u monat!=$monat\u l){
如果($divOpen)
回声';
回声';
$divOpen=true;
回音“.$monat[$ts_monat]”;
}
$monat_l=$ts_monat;
这里是内容
如果($divOpen)
回声';
您可以使用布尔变量$divOpen
跟踪
是否打开。。。
$divOpen=false;
而($loop->have_posts()):$loop->the_post();
$timestamp=get_post_meta($post->ID,'u tatort_datum',true);
$ts_jahr=strftime(“%Y”,$timestamp);
如果($ts_jahr!=$jahr_l){
如果($divOpen){
回声';
$divOpen=false;
}
回声“.$Tsu jahr.”;
}
$jahr_l=$ts_jahr;
$ts_monat=strftime(“%m”,$timestamp);
如果($ts\u monat!=$monat\u l){
如果($divOpen)
回声';
回声';
$divOpen=true;
回音“.$monat[$ts_monat]”;
}
$monat_l=$ts_monat;
这里是内容
如果($divOpen)
回声';
$divOpen = false;
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) {
if ($divOpen) {
echo '</div>';
$divOpen = false;
}
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) {
if ($divOpen)
echo '</div>';
echo '<div class="month">';
$divOpen = true;
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(); ?>
if ($divOpen)
echo '</div>';