编码Wordpress / PHP问题

时间:2011-07-08 13:59:21

标签: 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->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'));
        ?>

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

继承人凭证div

<?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

无法解决,所有帮助表示赞赏,

由于 乔

1 个答案:

答案 0 :(得分:1)

更改

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

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

尝试运行以下内容作为其不同之处的示例:

$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));

编辑:或者如果你想要精确的时间戳到最短的时间,可以使用strtotime(“now”)