WordPress.org

Ready to get started?Download WordPress

Forums

Header based on date? (18 posts)

  1. Arash
    Member
    Posted 7 years ago #

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

  2. GOBLUE14
    Member
    Posted 7 years ago #

    Not sure about a plug-in, but if you know (or are willing to work with) PHP, this might be able to be tweaked to achieve a similar result:

    http://bonrouge.com/br.php?page=faq#time-pic

  3. Arash
    Member
    Posted 7 years ago #

    Thanks GOBLUE14, I don't know php :(

  4. GOBLUE14
    Member
    Posted 7 years ago #

    It's not too bad. Might take some trial and error, but finding out what the various parts of that code mean and switching them out shouldn't be too bad. I don't know all that much PHP either, but I've learned a ton by deconstructing WP themes and code like this.

    I couldn't find it in a brief Googling earlier, but I have seen a Javascript example that changes the whole look of the page (swaps CSS files) depending on what time of day it is, if you know Javascript better, you could probably achieve a similar result.

  5. Arash
    Member
    Posted 7 years ago #

    I did find a header rotation plugin http://mhough.com/wordpress/2007/header-image-rotator-plugin/

    But it is not based on date. So I am going to see if I can find someone that can combine that rotation plugin, with the link you send me.

  6. GOBLUE14
    Member
    Posted 7 years ago #

    I still haven't tried it, but the link I sent could probably be switched so that you have a different theme each month, and possibly further to get into a range of dates within a month (or a specific day, kind of like Google does with their header images on holidays).

    Unfortunately, I'm not as skilled as I thought to try to make all of that happen quite yet, but I might play around with it.

  7. Arash
    Member
    Posted 7 years ago #

    Maybe someone else will see this post and help out :)

  8. Arash
    Member
    Posted 7 years ago #

    I've tried http://codex.wordpress.org/Conditional_Tags but so far no luck

  9. Arash
    Member
    Posted 7 years ago #

    Does anyone have a clue?

  10. kukyideas
    Member
    Posted 7 years ago #

    Sorry I don't have an answer for you. I really hope someone figures this out. I don't know php either. Fiddling around the closest I got was changing one specific single page using is_single().

  11. mrmist
    Forum Janitor
    Posted 7 years ago #

    There's a number of ways you could do this, but the easiest would most likely be a bit of PHP in the theme header. All you'd need would be an if..else block comparing the results of getdate() with your required parameters.

  12. kukyideas
    Member
    Posted 7 years ago #

    Hey John, I think you're in the same boat as I am. I'm trying to learn PHP but when you don't know what something is called you can't google it. And then looking for "if else" and "getdate" pulls up stuff that I just don't understand (not for beginners).

    But I've been fiddling around and have come up with something. I don't know how to use less than or between these two numbers so I wrote each date out separately. I don't even know what's possible. If someone knows how to do that please share. I didn't know how to google it.

    Ok, I'm going to break it all down just in case you are totally lost like I was. Sorry this reply is so long.

    So here goes. First I copied my header.php file and replaced my regular header jpg with my holiday header jpg. Then I renamed it holidayheader.php

    Then in my single.php file and archive.php file (I had to do that in the single.php file and archive.php because otherwise it wouldn't work when I was navigating through my calendar) I replaced <?php get_header();?> with

    <?php $holidayheader = get_the_time('nj');  ?>
    	<?php if ($holidayheader == 1215){ ?>
    	<?php include (TEMPLATEPATH .'/holidayheader.php'); ?>
    	<?php } else if ($holidayheader == 1216) { ?>
    	<?php include (TEMPLATEPATH .'/holidayheader.php'); ?>
    	<?php } else if ($holidayheader == 1217) { ?>
    	<?php include (TEMPLATEPATH .'/holidayheader.php'); ?>
    	<?php } else if ($holidayheader == 1218) { ?>
    	<?php include (TEMPLATEPATH .'/holidayheader.php'); ?>
    	<?php } else if ($holidayheader == 1219) { ?>
    	<?php include (TEMPLATEPATH .'/holidayheader.php'); ?>
    	<?php } else if ($holidayheader == 1220) { ?>
    	<?php include (TEMPLATEPATH .'/holidayheader.php'); ?>
    	<?php } else if ($holidayheader == 1221) { ?>
    	<?php include (TEMPLATEPATH .'/holidayheader.php'); ?>
    	<?php } else if ($holidayheader == 1222) { ?>
    	<?php include (TEMPLATEPATH .'/holidayheader.php'); ?>
    	<?php } else if ($holidayheader == 1223) { ?>
    	<?php include (TEMPLATEPATH .'/holidayheader.php'); ?>
    	<?php } else if ($holidayheader == 1224) { ?>
    	<?php include (TEMPLATEPATH .'/holidayheader.php'); ?>
    	<?php } else if ($holidayheader == 1225) { ?>
    	<?php include (TEMPLATEPATH .'/holidayheader.php'); ?>
    	<?php } else { ?>
    	<?php get_header();?>
    <?php } ?>

    And that seemed to do the trick. Changed the header between 15 and 25 december.

  13. Arash
    Member
    Posted 6 years ago #

    WoW kukyideas! It seems you are on to something. I am going to try it and see if it also works for my blog.

  14. kukyideas
    Member
    Posted 6 years ago #

    Hey John rereading your post now I'm wondering if I misunderstood your question. Did you mean to change the header based on the real date and not the post date? Because my solution is for changing the header based on the post date.

    Oh and if it was the post date you were looking for I figured out the less than more than thing. You should be able to use this simplified version instead:

    <?php $holidayheader = get_the_time('nj');  ?>
    	<?php if ($holidayheader >= 1215 && $holidayheader <= 1225){ ?>
    	<?php include (TEMPLATEPATH .'/holidayheader.php'); ?>
    	<?php } else { ?>
    	<?php get_header();?>
    <?php } ?>
  15. Arash
    Member
    Posted 6 years ago #

    Hi kukyideas,

    I am looking for the real date.

  16. kukyideas
    Member
    Posted 6 years ago #

    Hey John,

    I think I figured something out for real date. You might want to test it in real time though. Like put a hidden page up somewhere and change the dates in the code below to check it maybe the first two weeks of October. So here it is:

    <?php $holidayheader = getdate() ?>
    
    	<?php if ($holidayheader[mon] = 12 && $holidayheader[mday] > 15 && $holidayheader[mday] < 26){ ?>
    	<?php include (TEMPLATEPATH .'/holidayheader.php'); ?>
    	<?php } else { ?>
    	<?php get_header();?>
    <?php } ?>
  17. Tfleming
    Member
    Posted 6 years ago #

    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.

  18. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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. :)

Topic Closed

This topic has been closed to new replies.

About this Topic