• I’m looking for some method/plugin that would allow my blog to display an image next to a post’s title, but only for posts that are newer than X days/hours old. For insance, I would like a “New post” image to appear for every post on my blog that is 24 hours old or newer. Of course, the time should be configurable.

    Is there a plugin or hack that would allow me to do this quickly? Or should I be looking for some PHP code? (I’m a PHP n00b.)

    (If you reply with a “do a search first” message (which I have done), please give me some search terms that would bring up appropriate posts. Thanks.)

Viewing 10 replies - 1 through 10 (of 10 total)
  • This would be a good feature to add. I’ll search around and see what i can find.

    I don’t think there’s a plugin that currently does that…. but would be a nice addition.

    Tg

    I am looking for such a plugin as well. In case someone needs extra posts to ‘show a need’ before they work on it.

    Thread Starter Novac

    (@novac)

    To clarify, I guess I would like this for 1.5 strayhorn.

    davidchait

    (@davidchait)

    I have a ‘temperature gauge’ that I’ll be updating for 1.5 that might be easily adapted to show new posts as well.

    If you check out my site, I use ‘hot’ icons next to posts that have a certain ratio of pageviews-to-age, with a funky function to accelerate the falloff. I should probably accelerate it more, but it works for the moment. In fact, I SHOULD be using a few different icons, for hot, hotter, hottest sorta breakdown. Easy to link to certain ‘heat index’ boundaries in my nomenclature.

    But what I basically do is tack an img onto the header of the post — I’ll have to see if I can intercept that easily in 1.5. If not, previously (6 mos back) I did something similar tacked onto the meta heading (posted-by, or date, or something).

    -d
    CHAITGEAR

    philpeeps

    (@philpeeps)

    I was just searching for this too. I guess it could be done by just some if statements in the loop to apply a div class or id if it is less than x days/hours from the post date…

    but i don’t know php well enough to attempt it….

    Kafkaesqui

    (@kafkaesqui)

    Some if statement?

    <?php
    $hours = 24;
    $post_time = get_the_time('U', false);
    $now = time('U');
    $diff = ($now - $post_time) / 3600;
    if($hours > ceil($diff)) : ?>

    <img src="/PATH/TO/IMAGE.GIF" alt="NEW" title="NEW" />

    <?php endif; ?>

    Change the $hours variable to the number of hours you want the image to display.

    philpeeps

    (@philpeeps)

    Thanks Kafkaesqui! That works beautifully! Below is how I have it implemented on my site to sit next to the date of the post…

    <h2><?php the_date("","",""); ?>

    <?php
    $hours = 120;
    $post_time = get_the_time("U", false);
    $now = time("U");
    $diff = ($now - $post_time) / 3600;
    if($hours > ceil($diff)) : ?>

    <img src="/wp/wp-images/new.gif" alt="NEW" title="NEW" />

    <?php endif; ?></h2>

    Thread Starter Novac

    (@novac)

    AWESOME. Drop-in code rules. I knew if Kafkaesqui got wind of this request it would be well executed.

    Thanks K!

    Kafkaesqui

    (@kafkaesqui)

    “Drop-in code rules.”

    I think so. It could easily be written up as little plugin, but sometimes it’s good to see how things work (and all the better to modify).

    (Got wind? Eww. ;)

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Feature Request: Img for new posts only?’ is closed to new replies.