基于日期的WordPress的代码
问题描述:
我试图让Wordpress执行一些代码,如果发布日期晚于特定日期。当我使用以下内容时,它几乎可以正常工作......除了Worpress显示/回显日期而不是仅评估它。基于日期的WordPress的代码
<?php $date1 = '2013-03-22';
$date2 = the_date();
if ($date2 >= $date1) { ?>
//code to execute
<?php } ?>
任何想法?
答
结束了使用这样的事情:
$date2 = the_date('','','',FALSE);
if (strtotime($date2) >= strtotime($date1)) { code to execute }
答
它只是如何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; ?>
答
你也可以试试这个:
$date1 = '2013-03-22';
$date2 = get_the_date();
if ($date2 >= $date1) { ?>
//code to execute
<?php } ?>
get_the_date()
刚刚返回,而the_date()
打印后的日期。