Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>
            </ul>


            <?php
            $temp = $wp_query;
            $wp_query= null;
            $wp_query = new WP_Query();
            $wp_query->query('posts_per_page=10'.'&paged='.$paged);
            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>
                    <div class="pseudo-link">Accept</div>
                    </a>
                </article>

                <?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>
                        <div class="pseudo-link">Read more</div>
                        </a>
                    </article>

                <?php } ?>

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

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

                <?php } ?>

            <?php endwhile;?> 

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

            <?php $wp_query = null; $wp_query = $temp; wp_reset_query(); ?>
        </section>
share|improve this question

1 Answer 1

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

 
discard

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.