Support » Plugin: Ad Inserter - Ad Manager & AdSense Ads » Display ads based on time and week day

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Spacetime

    (@spacetime)

    You can easily achieve this with a simple PHP code that inserts ads based on time.

    Plugin Author Spacetime

    (@spacetime)

    Here is code example:

    <?php
    
    define ('HOUR', 17); // Switch ads on 17.00 (server time)
    $current_hour = date ('H');
    if ($current_hour >= HOUR) : ?>
    
    Ad code 1 (after hour)
    
    <?php else : ?>
    
    Ad code 2 (before hour)
    
    <?php endif; ?>

    1. Don’t forget to enable PHP processing
    2. The time is defined by the ‘HOUR’ constant – this is server time hour
    3. If you are using caching there may be some delay in switching due to serving cached (old) file

    Big thanks for your quick response and a working solution

    This is cool, how would you set it up to do days also?

    I need to replace ads for the Sabbath hours between sundown Friday night, and sundown Saturday night. (I realize it may be extremely difficult to track the actual sundown time, so I’ll probably have general summer and winter hours.)

    Thanks!

    Plugin Author Spacetime

    (@spacetime)

    Maybe something like this:

    <?php
    
    define ('SUNDOWN_FRIDAY', 20);   // Sundown on Friday (server time)
    define ('SUNDOWN_SATURDAY', 20); // Sundown on Saturday (server time)
    $current_hour = date ('H');
    $current_day_of_week = date ("N");
    if ($current_day_of_week == 5 && $current_hour >= SUNDOWN_FRIDAY || $current_day_of_week == 6 && $current_hour < SUNDOWN_SATURDAY) : ?>
    
    Sabbath code
    
    <?php else : ?>
    
    Normal Ad code
    
    <?php endif; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display ads based on time and week day’ is closed to new replies.