如果发布日期晚于特定日期,我正在尝试让Wordpress执行某些代码。当我使用以下内容时,它几乎可以工作......除了Worpress显示/回显日期而不是仅仅评估它。
<?php $date1 = '2013-03-22';
$date2 = the_date();
if ($date2 >= $date1) { ?>
//code to execute
<?php } ?>
有什么想法吗?
答案 0 :(得分:1)
这就是the_date()
的工作原理:
显示或返回帖子的日期,如果在同一天发布,则显示一组帖子
使用示例:
<?php the_date( $format, $before, $after, $echo ); ?>
因此,您必须将false
传递给函数才能打印日期,因为它默认为true
。例如:
<?php
$date1 = '2013-03-22';
$date2 = the_date('', '', '', FALSE);
if ($date2 >= $date1): ?>
Hello world!
<? endif; ?>
答案 1 :(得分:0)
你也可以试试这个:
$date1 = '2013-03-22';
$date2 = get_the_date();
if ($date2 >= $date1) { ?>
//code to execute
<?php } ?>
get_the_date()
只会在the_date()
打印发布日期时返回日期。
答案 2 :(得分:0)
结束使用这样的事情:
$date2 = the_date('','','',FALSE);
if (strtotime($date2) >= strtotime($date1)) { code to execute }