[英]PHP countdown with custom field in wordpress
I want to display the days remaining till the date specified in a custom field inside of wordpress. 我想显示到wordpress内部自定义字段中指定的日期为止的剩余天数。 My custom field is named
bewerbungs_frist
. 我的自定义字段名为
bewerbungs_frist
。 I'M using this code: 我正在使用此代码:
<?php $days = ceil((strtotime("<?php the_field('bewerbungsfrist'); ?>") - time())/(60*60*24));
$s='';
if ($days!=1) {
$s='s';
}
echo $days. " days "; ?>
As a output I get something like -1500 days. 作为输出,我得到-1500天。 That can't be right.
那是不对的。 Can somebody help me out?
有人可以帮我吗?
I solved the issue with this code: 我用以下代码解决了这个问题:
<p>Bewerbungsfrist: <?php $date = DateTime::createFromFormat('Ymd', get_field('bewerbungs_frist')); echo $date->format('d.m.Y');?></p>
noch <?php $days = ceil((strtotime(get_field('bewerbungs_frist')) - time())/(60*60*24));
echo $days. " Tage "; ?>
You are opening wrong php tags between already opened tags 您正在打开的标签之间打开错误的php标签
try this 尝试这个
$days = ceil((strtotime(the_field('bewerbungsfrist')) - time())/(60*60*24));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.