0
我想要动态地实现下面的HTML:如何设置处理不同范围值的不同数组?
时间段AD:
<ul>
<li>1200</li>
<li>1300
<ul>
<li>1301</li>
</ul>
<li>
</ul>
时间段BC:
<ul>
<li>-200</li>
<li>-450
<ul>
<li>-451</li>
</ul>
</li>
</ul>
在下面我已经设置的阵列,以便我可以通过使用一些自定义字段将我的日期推入数组,然后告诉整个代码在100年内计算,以便能够将1301
这样的年份作为1300
下的嵌套ul。
<ul>
<?php
$yearsArray = [];
$centuryHash = [];
query_posts(array(
'post_type' => 'post',
'posts_per_page' => -1
));
while (have_posts()) : the_post();
array_push($yearsArray, get_field("year"));
if (($wp_query->current_post +1) == ($wp_query->post_count)) {
$yearsArray = array_unique($yearsArray);
sort($yearsArray);
}
endwhile;
foreach ($yearsArray as $year) {
$currentCentury = floor($year/100)*100;
if(!$centuryHash[$currentCentury]){
$centuryHash[$currentCentury] = [];
}
if($currentCentury != $year){
$centuryHash[$currentCentury][] = $year;
}
}
foreach ($centuryHash as $century => $centuryYears) { ?>
<li class="dropdown">
<?php if($centuryYears){ ?>
<a class="btn btn-default" href="#" class="dropdown-toggle" data-date="<?php echo $century; ?>" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<?php echo $century; ?>
<span class='caret'></span>
</a>
<ul class='dropdown-menu'>
<?php foreach ($centuryYears as $year) { ?>
<li>
<a class="btn btn-default" data-date="<?php echo $year; ?>" href="#">
<?php echo $year; ?>
</a>
</li>
<?php }
echo "</ul>";
} else { ?>
<a class="btn btn-default" data-date="<?php echo $century; ?>" href="#">
<?php echo $century; ?>
</a>
<?php } ?>
</li>
<?php }
?>
</ul>
,我无法弄清楚的问题是我怎么能说像(文字代码):
如果值是-450至2的范围内,则进入此阵,否则去该阵列中,而不是
从我结束我能在CMS设置(人们将能够插入带有日期的内容)的一些标志,这样我可以做一些简单的条件语句像(文字代码):
“这个日期是来自a还是b?然后做这样或那样的”
但是,因为我的标志一段时间和地点的错误的日期在错误的时间段产生的问题。
因此,我认为最后的解决办法是设置一系列的时间段,并通过创建不同的分隔符来创建不同的分组,我可以根据它们的值动态推送这些分组。什么去那里?
foreach (range(0, 12) as $number) {
echo $number;
}
谢谢,这是有道理的,它其实很简单,也许我只是上面的整个代码重载。 –