• Resolved kcberlin

    (@kcberlin)


    Outside of a default header image, how could I set a different image depending on the month in archive view (/2013/05/ different from /2013/06/ for example)? I would also like this to apply to individual posts, like the May 2013 image applying to /2013/05/individual-posts/

Viewing 4 replies - 1 through 4 (of 4 total)
  • is that a header background image or a html img tag image?

    what theme are you using?

    would /2012/05/ need to be different from /2013/05/ ?

    Thread Starter kcberlin

    (@kcberlin)

    I am using a customised HTML5 Reset theme. I could make it a CSS background image or an HTML image tag, whatever works.

    to use with a background image, you can consider to inject the month/year as a custom class into the body_class();

    http://codex.wordpress.org/Function_Reference/body_class#Add_Classes_By_Filters

    example, assuming the background image is in the .header element:

    add_filter( 'body_class', 'month_and_year_body_class' );
    
    function month_and_year_body_class( $classes ) {
      if( is_month() || is_single() ) {
        $classes[] = 'year-' . get_the_date( 'Y' );
        $classes[] = 'month-' . get_the_date( 'm' );
      }
    return $classes;
    }

    style.css;

    example:

    .year-2013.month-05 .header {
       background-image: url('images/header-may-2013.jpg');
    }

    [corrected]

    untested

    Thread Starter kcberlin

    (@kcberlin)

    I put the add_filter bit in functions.php and changed the CSS so it says ‘url’ instead of ‘src’ for the background-image, and it works great, thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Change header image depending on monthly archive and month post was published’ is closed to new replies.