WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Basically I'm looking to add this line of code to posts published within the last 24hrs:

<span class="new">New!</span>

When the post is over 24hrs old, remove the inline HTML element.

This is my code so far but have no idea how to implement this feature, anybody got any ideas?

<section class="post-wrap">

            <ul class="filter">
                <li><a href="<?php bloginfo( 'url' ); ?>/explorers">All</a></li>
                <li><a href="<?php bloginfo( 'url' ); ?>/category/stories" class="stories">Stories</a></li>
                <li><a href="<?php bloginfo( 'url' ); ?>/category/missions" class="missions">Missions</a></li>
                <li><a href="<?php bloginfo( 'url' ); ?>/category/questions" class="questions">Questions</a></li>

            $temp = $wp_query;
            $wp_query= null;
            $wp_query = new WP_Query();
            while ($wp_query->have_posts()) : $wp_query->the_post();

                <?php if (in_category(3)) {?>

                <article class="mission" id="post-<?php the_ID(); ?>">
                    <a href="<?php the_permalink(); ?>">    
                        <div class="headline">              
                            <h1><?php the_title(); ?> <span><?php echo get_the_date(); ?></span></h1>
                            <?php global $more; $more = 0; the_content(''); ?>
                    <div class="pseudo-link">Accept</div>

                <?php } ?>

                <?php if (in_category(4)) {?>

                    <article class="story" id="post-<?php the_ID(); ?>">
                        <a href="<?php the_permalink(); ?>">    
                            <span class="new">New!</span>
                            <div class="headline">              
                                <h1><?php the_title(); ?> <span><?php echo get_the_date(); ?></span></h1> 
                                <p><?php the_field('author_details'); ?></p>
                        <div class="pseudo-link">Read more</div>

                <?php } ?>

                <?php if (in_category(5)) {?>

                    <article class="question" id="post-<?php the_ID(); ?>">
                        <h2><?php the_title(); ?></h2>

                <?php } ?>

            <?php endwhile;?> 

            <div class="next-prev">
                <?php next_posts_link('Older Posts') ?>
                <?php previous_posts_link('Newer Posts') ?>

            <?php $wp_query = null; $wp_query = $temp; wp_reset_query(); ?>
share|improve this question
up vote 2 down vote accepted

Compare the current time with the UNIX time stamp of the post date:

// now minus one day in seconds
if ( ( time() - 86400 ) < get_the_date( 'U' ) )
    echo '<span class="new">New!</span>';
share|improve this answer
You beat me to it! Darn needing to look up date() formats! – guiniveretoo Sep 5 '12 at 1:19
Perfect. Thank you! – egr103 Sep 6 '12 at 9:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.