开发者

Coding Wordpress/PHP Problem

开发者 https://www.devze.com 2023-03-18 02:08 出处:网络
Im having a bit of a problem with wordpress. On my site there is a bit that displays voucher now what i want is when开发者_如何学JAVA that voucher expires i want the voucher details div not too show.

Im having a bit of a problem with wordpress. On my site there is a bit that displays voucher now what i want is when开发者_如何学JAVA that voucher expires i want the voucher details div not too show.

Here is the code from 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'));
        ?>

this brings all the data from custom fields

heres the voucher 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 }?>

Now when i run this with the expiry with any value the voucher doesn't show The value in store is DD/MM/YYYY

Can't work it out, all help appreciated,

Thanks Joe


Change

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

to be

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

Try run the following as an example of how it differs:

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

Edit: Alternatively use strtotime("now") if you want the precise timestamp to the very minute

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号