I am using Scheduler module in order to enable unpublish date for a content type.

Now I want to create countdown timer for the nodes that unpublish date is set for them.

I checked jQuery Countdown and Countdown Timer Field modules but it seems they can't help in this issue.

What is your suggestion? Is there any way to create a relation between node unpublish date and countdown_timer modules or I must edit source of themes?

Thanks a lot for your help

  • Hello. Have you tried anything already? jquery_countdown_add of jQuery Countdown module you named in your question should be enough. What's wrong with it? – Mołot Oct 7 '13 at 14:03
  • Thanks for you reply. I know that I can do this with editing html codes of tpl files. To do this I can add js files and javascript codes to the tpl file of selected node. But if I use this solution, I have to edit all theme files and this is not good. So I want to do a basic solution. Tell me please is jquery_countdown_add is a module or it is a function? Thanks a lot for your help. – Mehrdad201 Oct 7 '13 at 14:26
  • You only need to edit tpl file of your content type and make jquery_countdown_add use a date from a field. For unpublished, allow everyone to see, but in tpl hide anything but timer for those who shouldn't see it yet. – Mołot Oct 7 '13 at 14:31

You could add the snippet below as a new module scheduler_unpublish_countdown. It defines a block which you can shown on the node page of any content type you choose and allow it to countdown to the scheduled unpublish time for that node. As the block that comes with the jquery_countdown module counts down to a global event; this might be better for your use case.


 * Implements hook_block_info().
function scheduler_unpublish_countdown_block_info() {
  return array(
    'unpublish_countdown' => array(
      'info' => t('Scheduler Unpublish Countdown'),
      'cache' => DRUPAL_NO_CACHE

 * Implements hook_block_view().
function scheduler_unpublish_countdown_block_view($delta) {
  if ($delta == 'unpublish_countdown') {
    $node = menu_get_object();
    // Ignore non-node pages, already unpublished nodes, nodes that don't have a 
    // date/time set for unpublishing and nodes whose unpublishing date-time is in the past.
    if (!$node || 
      empty($node->status) || 
      empty($node->scheduler['unpublish_on']) || 
      ($node->scheduler['unpublish_on'] <= REQUEST_TIME)) {
    $variables = array(
      'id' => drupal_html_id('jquery_countdown-' . $delta),
      'options' => array(
        'until' => date("F d, Y g:i a", $node->scheduler['unpublish_on']),
        'description' => ' ', // So that the CSS doesn't get screwed
        // Reload the page when the countdown is done
        'onExpiry' => '(function() { location.reload(); })', 
    return array(
      'subject' => t('Scheduled unpublish in..'),
      'content' => theme('jquery_countdown', $variables)

Once the countdown is complete, the page will simply reload (see onExpiry option above). As unpublishing happens only either during the normal Drupal cron run or through the Scheduler's own light-weight variant, it may not happen exactly at the time of unpublishing meaning the page would reload and nothing would happen (except for the timer not showing up anymore) which might be slightly awkward.

I'd recommend, therefore, to redirect to a custom page once the countdown expires where you explicitly call _scheduler_unpublish() and then redirect back to the node page. You might want to send a one-time-only token along for security.

Remember to add scheduler and jquery_countdown as dependencies for your new module.

| improve this answer | |
  • thanks a lot fro your solution. I will try your code as soon as possible. But I have a question. in "onExpiry" event, are we able to run cron? because after run cron, the expired node (base on unpublish date) will be hidden. – Mehrdad201 Oct 7 '13 at 15:06
  • onExpiry is a Javascript callback - so, no, you probably won't be able to run cron but you can redirect to a custom page with a token from which you can then call scheduler_cron() or more specifically _scheduler_unpublish(). Alternatively, you can make an AJAX request once the countdown expires to the same page (as above) and respond as you see fit. – Amarnath Ravikumar Oct 7 '13 at 16:06
  • Dear Amarnath Ravikumar. Thanks a lot for your solution. It works fine but this block only works on node page. if you have multiple nodes (that each of them has different unpublish date) in a single page that are collected via a view this blocks can't work. Also my plan is inject the counter into view field. I created a view that collect all nodes that have unpublish date (and status is published) and there is field named "unpublish countdown" that shows seconds till timer finish date/time. Do you have any solution for this scenario? Thanks a lot in advance for your help. – Mehrdad201 Oct 7 '13 at 17:45

Is the provided solution still operational? I've enabled it as submodule, but I don't seem to see any difference (config / display) after enabling it. Am I overlooking something that should be done before it should work?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.