• Resolved morgyface

    (@morgyface)


    Hello. I love this plug-in, it’s magic.

    I just wondered if there was a way of doing something like this within a template using PHP…

    if CSSable Countdown has expired then display this section if not show CSSable Countdown.

    I’m aware of do_shortcode but hoping there’s a way of doing more with the plug-in with PHP within templates.

    https://wordpress.org/plugins/cssable-countdown/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author dmonnier

    (@dmonnier)

    Thanks for the kind words 🙂

    You can use HTML in the expiry text field, but in order to use the plugin as-is in a template, you’ll still have to use do_shortcode().

    // check if the target date is expired
    if ( mktime( H,i,s,n,J,Y ) < mktime() ) {
    	// do expired stuff
    } else {
    	echo do_shortcode( '[countdown date="MM/DD/YYYY" ...]' );
    }

    (Of course, this doesn’t take into account timezones or countup versions… you can modify as necessary with gmmktime() and switch operands.)

    Alternatively, you can build the jQuery call yourself in templates. The plugin is built on top of Keith Wood’s jQuery Countdown (version 1.6.3), so if you have the plugin activated (or the jQuery scripts included), you can do something like this in your templates:

    <div id="cssable-countdown" class="cssable-countdown layout-type_default">
    	<!-- do stuff you want showing regardless of countdown status -->
    </div>
    
    <script type="text/javascript">
    jQuery(document).ready(function($) {
    	$('#cssable-countdown').countdown({
    		until: new Date(2015, 12, 31, 0, 0, 0, 0),
    		timezone: '-5',
    		format: 'yOWD',
    		alwaysExpire: 'true',
    		expiryText: '<div id="timeExpired"><!-- stuff you only want showing if expired --></div>',
    	});
    });
    </script>

    Does that help you?

    Thread Starter morgyface

    (@morgyface)

    It does help me immensely, thank you so much and apologies for taking so long to respond. In the end I used it like this:

    <?php
    date_default_timezone_set('Europe/London');
    $hour = 18;
    $minutes = 55;
    $seconds = 0;
    $month = 04;
    $day = 03;
    $year = 2014;
    $timestamp = mktime();
    $countdown = mktime($hour,$minutes,$seconds,$month,$day,$year); 
    
    if($countdown < $timestamp ) {
    
        echo '<p>Expired</p>';
    
    } else {
    
        echo do_shortcode( '[countdown date="' . $month . '/' . $day . '/' . $year . '" time="' . $hour . ':' . $minutes . ':' . $seconds . '"]' );
    }
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Expiry redirect in PHP.’ is closed to new replies.