Is it possible to set a CSS stylesheet or a theme for articles that were published before X date?

The reason I ask is that we've just redesigned our website and some pages have images that are wider than the page size now.

  • Why not use max-width CSS property on images? That will keep wider images within page size, and normal images aren't affected. – its_me Jun 28 '12 at 10:52

I php you can create an anchor class based on the desired date. I haven't tested it, but it should be something like this:

    // your relevant html parent element
    <div class="<?php echo getOlderPostsClassName( '5/5/2012',the_time() ); ?>">

    function getOlderPostsClassName($untilDate, $wordpressPostDate)
       $start = strtotime($untilDate);
       $end = strtotime($wordpressPostDate);
       if ($start-$end > 0)
          return 'My_css_class_for_older_posts';
       return '';

Then in your Css you can target differently any descendant element:

.My_css_class_for_older_posts h2{
| 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.