我正在尝试按日期对 foreach 语句中生成的数据进行分组。我正在使用 Kirby CMS,但在完成以下任务时遇到了麻烦。
目标(须藤):
date: 03/10/15
Take Over
date: 03/09/15
Video
Flash
Super GIF 2
Super GIF
Image
我的尝试:
date: 03/10/15
Take Over
date: 03/09/15
Video
date: 03/09/15
Flash
date: 03/09/15
Super GIF 2
date: 03/09/15
Super GIF
date: 03/09/15
Image
代码:
<ul>
<?php foreach($page->children()->visible()->sortBy('modified', 'desc') as $projects): ?>
<li>
date: <?php echo $projects->modified('m/d/y') ?> <br>
<a href="<?php echo $projects->url() ?>"><?php echo $projects->title()->html() ?></a>
</li>
<?php endforeach ?>
</ul>
第二次失败的尝试:
<ul>
<?php foreach($page->children()->visible()->sortBy('modified', 'desc') as $projects): ?>
<li>
<?php foreach($page->children()->visible()->sortBy('modified', 'desc') as $project): ?>
<?php
if($projects->modified('m/d/y') == $project->modified('m/d/y')) {
echo $project->modified('m/d/y') . '<br>' . $project->title();
}
?>
<?php endforeach ?>
</li>
<?php endforeach ?>
</ul>
输出:
03/10/15
Take Over
03/09/15
Video 03/09/15
Flash 03/09/15
Super GIF 2 03/09/15
Super GIF 03/09/15
Image
03/09/15
Video 03/09/15
Flash 03/09/15
Super GIF 2 03/09/15
Super GIF 03/09/15
Image
03/09/15
Video 03/09/15
Flash 03/09/15
Super GIF 2 03/09/15
Super GIF 03/09/15
Image
03/09/15
Video 03/09/15
Flash 03/09/15
Super GIF 2 03/09/15
Super GIF 03/09/15
Image
03/09/15
Video 03/09/15
Flash 03/09/15
Super GIF 2 03/09/15
Super GIF 03/09/15
Image