Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Luke Etheridge

    (@luke-etheridge)

    I got how to add the short code with…

    <?php echo do_shortcode('[postexpirator]'); ?>

    But now just need to know how to display as ‘Days Left’?

    Thanks.
    Luke

    Thread Starter Luke Etheridge

    (@luke-etheridge)

    Alsoooo…

    This is my code…

    <span class="expire"><?php echo do_shortcode('[postexpirator]'); ?></span>

    BUT, how do I have this only display when ‘Enable Post Expiration’ is checked for that specific post/post type?

    —–

    So if ‘Enable Post Expiration’ is checked display this…

    <span class="expire"><?php echo do_shortcode('[postexpirator]'); ?></span>

    If unchecked display nothing.

    Thread Starter Luke Etheridge

    (@luke-etheridge)

    OK so for the above ^ I’m doing…

    <?php if ( $expirationdatets ) { ?><span class="expire"><?php echo do_shortcode('[postexpirator]'); ?></span><?php } ?>

    Let me know if there is a better way please?

    The only question outstanding is how to display the expiration as ‘% Days Left’.

    Thanks.
    Luke

    Thread Starter Luke Etheridge

    (@luke-etheridge)

    Right, it appears I jumped the gun and I’m in fact my own support ??

    I’ve fixed all that I needed with the following…

    <?php
       $expirationdatets = get_post_meta($post->ID, '_expiration-date', true);
       $postid = $wp_query->post->ID;
       $date=get_post_meta($post->ID, '_expiration-date', true);
       $diff=$date-time();
       $days=floor($diff/(60*60*24));
    ?>

    And…

    <?php if ( $expirationdatets ) { ?>
    	<span class="expire" title="Offer Expiry">
    		<?php if ($days == '-15931') {
    		  echo ""; }
    		else if ($days == '0') {
    		  echo "<b>Expires within 24hrs</b>"; }
    		else if ($days == '1') {
    		  echo "<b>$days Day Left</b>"; }
    		else if ($days == '2') {
    		  echo "<b>$days Days Left</b>"; }
    		else if ($days == '3' || $days == '4' || $days == '5' || $days == '6' || $days == '7') {
    		  echo "$days Days Left"; }
    		else {
    		  echo do_shortcode('[postexpirator]'); }
    		?>
    	</span>
    <?php } ?>

    Please let me know if there is a better/cleaner way to achieve exactly that of the above, as you can probably see my PHP is not at it’s best ??

    Thanks,
    Luke

    Hi Luke, you seem like a genius!

    Should I insert this code into the page template? Where did you place your code? Have you got a visual example as well?

    Love your work!

    Thread Starter Luke Etheridge

    (@luke-etheridge)

    Hey Mediamojo13,

    Thanks for the kind words!

    Nah definitely no genius – not in PHP anyway ??

    All you have to do is insert the above code inside the loop of your template file and away you go. This will simply display the following…

    1 > ‘Expires within 24hrs’ (wrapped in <b>)
    2 > ‘1 Day Left’ (wrapped in <b>)
    3 > ‘2 Days Left’ (wrapped in <b>)
    4-7 > ‘% Days Left’
    7 < ’24th October 2013′ (normal postexpirator display)

    I’ll give you a visual when it’s live but it may not be for a month or so.

    Let me know if you have any problems.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display expiration outside post/page within template files.’ is closed to new replies.