• Is there plugin that can show a different header based on the date? For example showing a christmas header between 15 and 26 december?

Viewing 2 replies - 16 through 17 (of 17 total)
  • Kukyideas – thanks so much for this! I was looking for something very similar to allow me to switch out my sidebars and I was able to use your code for that.

    Anyone else wanted to do the same.. here’s what i did using Cutline theme with a left sidebar to switch over a five-day period).

    First, make 5 copies of your l_sidebar.php file.

    Rename each one, l_sidebar_mo.php for Monday’s version, l_sidebar_tu.php for Tuesday’s version, and so on.

    In your index.php, single.php and archive.php files, replace

    <?php include (TEMPLATEPATH . ‘/l_sidebar.php’); ?>

    with

    <?php $sidebar = get_the_time(‘nj’); ?>
    <?php if ($sidebar == 1015){ ?>
    <?php include (TEMPLATEPATH . ‘/l_sidebar_mo.php’); ?>
    <?php } else if ($sidebar == 1016) { ?>
    <?php include (TEMPLATEPATH . ‘/l_sidebar_tu.php’); ?>
    <?php } else if ($sidebar == 1017) { ?>
    <?php include (TEMPLATEPATH . ‘/l_sidebar_we.php’); ?>
    <?php } else if ($sidebar == 1018) { ?>
    <?php include (TEMPLATEPATH . ‘/l_sidebar_th.php’); ?>
    <?php } else if ($sidebar == 1019) { ?>
    <?php include (TEMPLATEPATH . ‘/l_sidebar_fr.php’); ?>
    <?php } else { ?>
    <?php include (TEMPLATEPATH . ‘/l_sidebar.php’); ?>
    <?php } ?>

    Populate each sidebar with what you want to appear that day. (The days above are for a five-day window in October.)

    If the post’s date doesn’t match any of the dates set, it will default to the regular l_sidebar.php.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Tfleming: There is a simpler way…

    <?php
    $template_filename = 'l_sidebar';
    $template = get_query_template($template_filename.'_'.get_the_time('md'));
    if (!empty($template)) include($template);
    else include(get_query_template($template_filename));
    ?>

    If you use this, you can name your files like so:
    l_sidebar_1015.php <- Oct 15
    l_sidebar_1016.php <- Oct 16
    … etc …

    And any files that are simply not there will revert to the l_sidebar.php template. This allows it to be highly flexible, as you can leave out any days you like and adjust them on the fly and such, without changing the code. Just don’t put the file there with the proper number and it will default back to the normal sidebar. Easy.

    Note that this requires leading zeros. So Jan 1st would be 0101. This makes it easy for you to keep things in order in the directory. Also avoids confusion about whether 121 is Jan 21st or Dec 1st. ??

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Header based on date?’ is closed to new replies.