编写Wordpress/PHP问题

编写Wordpress/PHP问题,php,wordpress,date,Php,Wordpress,Date,我对wordpress有点问题。在我的网站上,现在有一个显示凭证的功能。我想要的是,当凭证过期时,我希望凭证详细信息div不太显示 下面是single.php中的代码 <?php if(have_posts()) : while (have_posts()) : the_post(); $image = get_post_meta($post->ID, 'image',true); $writer = get_post_meta($post->

我对wordpress有点问题。在我的网站上,现在有一个显示凭证的功能。我想要的是,当凭证过期时,我希望凭证详细信息div不太显示

下面是single.php中的代码

<?php if(have_posts()) : while (have_posts()) : the_post();


        $image = get_post_meta($post->ID, 'image',true);
        $writer = get_post_meta($post->ID, 'writer',true);
        $code = get_post_meta($post->ID,'vcode',true);
        $store = get_post_meta($post->ID,'store',true);
        $expiry = strtotime(get_post_meta($post->ID,'expiry',true));
        $desc = get_post_meta($post->ID,'description',true);
        $datetoday = strtotime(date('Y/m/d'));
        ?>

这将带来来自自定义字段的所有数据

这是凭单部

<?php if($expiry > $datetoday){?>
        <div class="voucherDetails">
            <h2>Voucher Details</h2>
            <div class="left">
                <ul>
                    <li>Code: <?php echo $code;?></li>
                    <li>Expires: <?php echo $expiry;?></li>
                    <li><a class="more-link" href="<?php echo $store;?>" title="Visit Store">Visit Store!</a></li>
                </ul>
            </div>
            <div class="desc right">
                <h4>Description</h4>
                <p><?php echo $desc;?></p>
            </div>
        </div>
        <?php }?>

凭证详细信息
  • 代码:
  • 到期日:
描述

现在,当我使用任何值运行这个到期日时,凭证不会显示存储中的值是DD/MM/YYYY 无法解决,感谢大家的帮助

谢谢 乔改变了

  $datetoday = strtotime(date('d/m/Y'));
将来

尝试运行以下示例,以了解其区别:

$datetoday = strtotime(date('d/m/Y'));
var_dump($datetoday);
var_dump(date("F j, Y, g:i a", $datetoday));


$datetoday = strtotime(date('Y/m/d'));
var_dump($datetoday);
var_dump(date("F j, Y, g:i a", $datetoday));

编辑:或者使用strotime(“now”),如果您希望精确到每分钟的时间戳

在您的if语句之前,
$expiry
$datetoday
的值是多少?添加了主要问题中的值:)不过,公平地说,最安全的方法是使用ISO 8601格式。请参见以下摘自php.net的内容:通过查看各个组件之间的分隔符,可以消除m/d/y或d-m-y格式中的日期歧义:如果分隔符是斜杠(/),则假定为美式m/d/y;而如果分隔符是破折号(-)或点(.),则假定为欧洲d-m-y格式。为了避免潜在的歧义,最好在可能的情况下使用ISO 8601(YYYY-MM-DD)日期或DateTime::createFromFormat()。尝试仍然没有成功,如果我更改格式会不会影响整个站点?请参阅我现在的代码编辑:)谢谢:)您可以发布存储在这些变量中的实际值吗?为了满足我的好奇心,你可以发布以下代码的输出:
这是你发布的代码的输出:string(15)“TodayTimeStamp:”int(1310342400)string(10)“TodayConv:”string(23)”2011年7月11日,12:00 am“string(8)”Expiry:“string(0)”“string(17)”ExpiryTimestamp:“bool(false)string(12)”ExpiryConv:”string(23)“2011年7月11日,12:00 am”到期日应输出2011年7月8日,在本例中:S这是我在自定义字段中输入的日期。
$datetoday = strtotime(date('d/m/Y'));
var_dump($datetoday);
var_dump(date("F j, Y, g:i a", $datetoday));


$datetoday = strtotime(date('Y/m/d'));
var_dump($datetoday);
var_dump(date("F j, Y, g:i a", $datetoday));