定义以前的帖子时间php

时间:2014-06-03 16:23:01

标签: php rss

我有一个日历活动列表。现在,如果它与前一天不同,它只发布一天。因此所有周日活动列表都在一个"星期日"标题等我试图设置时间标题以同样的方式行事。即,仅列出一次的时间,以及该标题下面的所有相应事件。如何定义前一个时间,以便只有在新的时间内才能回显时间?

<?php
            $started_loop = false;
            $previousDay = 0;
            $sameDay = false;
            foreach($this->occurrences->channel->item as $occurrence) {

                // Extract time stamp from description
                $day = $this->getTimeStampFromDescription($occurrence->description);
                $imageURL = $this->getIMGURLFromDescription($occurrence->description);

                $dayDate = date('d', $day);
                $sameDay = ( ($dayDate == $previousDay) ? true : false);    // Set whether or not the post is the same day as the last one                              

                if($n > $max_events)
                    break;              // Stop loop if we've reached the maximum number of allowable events

                ?>

                <!-- Second eventful day of the week (Identical) -->
                <div class="row-fluid">

                    <div class="span9">
                    <h3 class="event_week_day"><?php if (!$sameDay) echo date('l, M j',$day); ?></h3>

                        <!-- First event for the day -->
                        <a href="<?php echo $occurrence->link ?>">
                            <p class="event_week_single">
                                <b><?php echo(date('g:i A ',$day) )?></b><br><?php echo ($occurrence->title); ?>
                            </p>
                        </a>

                    </div>
                </div>

1 个答案:

答案 0 :(得分:0)

替换:

$previousDay = 0;
$sameDay = false;

...

$dayDate = date('d', $day);
$sameDay = ( ($dayDate == $previousDay) ? true : false);

...

<?php echo(date('g:i A ',$day) )?>

使用:

$previousDay = 0;
$previousHour = 0;
$sameDay = false;
$sameHour = false;

...

$dayDate = date('d', $day);
$dayHour = date('g:i A', $day);
if ( $dayDate == $previousDay ) {
    $sameDay = true;
else {
    $sameDay = false;
    $previousHour = 0;
    $previousDay = $dayDate;
}
if ( $dayHour == $previousHour ) {
    $sameHour = true;
else {
    $sameHour = false;
    $previousHour = $dayHour;
}

...

<?php if (!$sameHour) { echo date('g:i A ',$day); } ?>