• Hello,

    I’m in search of a hack, that will add the word “new” next to the post title for a specific time range (e.g. 1 day). Any ideas how can I do this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • you could use some code like this:

    <?php if( (time() - get_the_time('U')) < (24*60*60) ) { echo 'new '; }; ?>

    the numbers above are for: 24 hours * 60 minutes * 60 seconds

    https://uk2.php.net/manual/en/function.time.php
    https://codex.www.ads-software.com/Function_Reference/get_the_time
    https://uk2.php.net/manual/en/function.date.php

    Thread Starter giankar

    (@giankar)

    So do I put this code next to the title function?

    Thread Starter giankar

    (@giankar)

    Actually where do I put that code? Can I also use it for displaying the word “new” next to category?

    this is the post title line from the default theme’s index.php:
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

    you could add the code like this:
    <h2><?php if( (time() - get_the_time('U')) < (24*60*60) ) { echo 'new '; }; ?><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

    the ‘new’ would appear in the same line as the title, but not linked.

    Can I also use it for displaying the word “new” next to category?

    as long as it is in the loop, you could put that code anywhere; just be aware the the term ‘new’ refers to the creation date of the post.

    Thread Starter giankar

    (@giankar)

    alchymyth thank you very much for your useful information

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘“New” next to the post title’ is closed to new replies.