WordPress.org

Forums

Suggestion for Plugin: Mark Expired posts with watermark (6 posts)

  1. hotice
    Member
    Posted 6 years ago #

    Hi,
    I have a suggestion for a WordPress plug-in:

    Have one that marks expired posts with an "Expired" (user defined jpg/art?) watermark over the general post area...

  2. Dagon Design
    Member
    Posted 6 years ago #

    Here is one quick method for you. This function can be used to add an extra CSS declaration to the element you choose if the post is older than a specified number of days:

    <?php
    $date_check_code = '';
    if (is_single()) {
      $days = 90;
      if (time() - strtotime($posts[0]->post_date_gmt) > ($days * 86400)) {
        $date_check_code = ' class="expired" ';
      }
    }
    ?>

    As you can see, the number of days is set to 90 in this example. And if the post being viewed is older than that, it sets the $date_check_code variable to ' class="expired" '

    You can then use that class on whatever you want, such as the div for the post. Here is an example for the default theme - replace this:

    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">

    With this:

    <div <?php echo $date_check_code; ?> <?php post_class() ?> id="post-<?php the_ID(); ?>">

    Of coure you can apply the extra CSS to any element, and define the .expired class however you like in your themes CSS file.

    Btw, this code is meant to be used in your themes single.php - for when viewing a full post.

    Should be a start to get you going :)

  3. callumalden
    Member
    Posted 6 years ago #

    Dragon Design, you are a bloody little genius. Thank you!

  4. WordPrezz
    Member
    Posted 6 years ago #

    What about dictating when the post expires through a date provided in a field in each post? Is that doable using this method or would a plugin be necessary in that circumstance?

    I know there's a Post Expirator plugin, but I'd like to keep my expired posts up and published, just greyed out or something along those lines.

  5. Dagon Design
    Member
    Posted 6 years ago #

    You could certainly do the same type of thing for that. Just use a custom post value, and retrieve it in the code, comparing it against the current date.

  6. WordPrezz
    Member
    Posted 6 years ago #

    Thanks, Dagon. I sent you an email through your site about seeing if you might be able to help me on this.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.