我使用以下代码作为转发器字段,该字段也有一个日期选择器。我想隐藏比当前日期更早的循环。
<?php if( have_rows('jobs','option') ): ?>
<div id="jobs">
<div class="jobs-title">
<h2><?php the_field('active','option'); ?></h2>
</div>
<div class="jobs">
<div class="inner-jobs flexing">
<?php while( have_rows('jobs','option') ): the_row(); ?>
<div class="flex job flexing">
<div class="flex-small">
<div class="bubble flex">
<img src="<?php the_sub_field('job-img','option'); ?>">
</div>
</div>
<div class="flex-cont">
<div class="job-title"><h4><?php the_sub_field('job-title','option'); ?></h4></div>
<p>Lõpptähtaeg: <?php the_sub_field('job-deadline','option'); ?></p>
<a href="<?php the_sub_field('job-url','option'); ?>" target="_blank"><button><?php the_sub_field('job-button','option'); ?><span class="ion-ios-arrow-forward"></span></button></a>
</div>
</div><!-- job -->
<?php endwhile; ?>
</div><!-- inner -->
</div><!-- .jobs -->
</div><!-- #jobs -->
<?php endif;?>
datepicker字段是&#39;作业截止日期&#39;
Haven还没有找到一个很好的例子,任何建议?
编辑:设法达到以下,仍然输出70/01/01
<?php if( have_rows('jobs','option') ): ?>
<?php $now = time(); ?>
<?php $date_one_timestamp = strtotime(get_sub_field('job-deadline','option')); ?>
<div id="jobs">
<div class="jobs-title">
<h2><?php the_field('active','option'); ?></h2>
</div>
<div class="jobs">
<div class="inner-jobs flexing">
<?php while( have_rows('jobs','option') ): the_row(); ?>
<?php if ($now > $date_one_timestamp ) { ?>
<div class="flex job flexing">
<div class="flex-small">
<div class="bubble flex">
<img src="<?php the_sub_field('job-img','option'); ?>">
</div>
</div>
<div class="flex-cont">
<div class="job-title"><h4><?php the_sub_field('job-title','option'); ?></h4></div>
<p>Lõpptähtaeg: <?php echo date("y/m/d", $date_one_timestamp); ?></p>
<a href="<?php the_sub_field('job-url','option'); ?>" target="_blank"><button><?php the_sub_field('job-button','option'); ?><span class="ion-ios-arrow-forward"></span></button></a>
</div>
</div><!-- job -->
<?php } else { ?>
<?php } ?>
<?php endwhile; ?>
</div><!-- inner -->
</div><!-- .jobs -->
</div><!-- #jobs -->
<?php endif;?>
答案 0 :(得分:0)
尝试下面的,未经测试的......
<?php if( have_rows('jobs','option') ): ?>
<div id="jobs">
<div class="jobs-title">
<h2><?php the_field('active','option'); ?></h2>
</div>
<div class="jobs">
<div class="inner-jobs flexing">
<?php while( have_rows('jobs','option') ): the_row(); ?>
<?php if(strtotime(get_sub_field('job-deadline','option'))<time()) { ?>
<div class="flex job flexing">
<div class="flex-small">
<div class="bubble flex">
<img src="<?php the_sub_field('job-img','option'); ?>">
</div>
</div>
<div class="flex-cont">
<div class="job-title"><h4><?php the_sub_field('job-title','option'); ?></h4></div>
<p>Lõpptähtaeg: <?php echo date("y/m/d", $date_one_timestamp); ?></p>
<a href="<?php the_sub_field('job-url','option'); ?>" target="_blank"><button><?php the_sub_field('job-button','option'); ?><span class="ion-ios-arrow-forward"></span></button></a>
</div>
</div><!-- job -->
<?php } else { ?>
<?php } ?>
<?php endwhile; ?>
</div><!-- inner -->
</div><!-- .jobs -->
</div><!-- #jobs -->
<?php endif;?>
答案 1 :(得分:0)
在have_rows()
循环内:
if ( date('d-m-Y', strtotime(get_sub_field('job-deadline','option'))) == "date('d-m-Y', strtotime('now')) ) {
continue;
}
将作业截止日期和当前日期转换为相同格式并进行比较。使用continue;
跳到循环的下一行。