• I want to put in New in posts that where added in todays date and when they are older than a day then go away I have tried this code but it is not working, You guys have any ideas?

    <?php $todaysdate= date('d/m/d');?>
    						<ul>
    							<?php foreach( $posts as $post ) : setup_postdata( $post ); ?><br />
    							<?php if (the_time('d/m/y' == $todaysdate)
    								{?>
    								<li <?php post_class(); ?>><small style="font-size: 9px; color: #0000FF;"><?php the_time('d/m/y'); ?></small> - <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    								<?php }
    								else
    								{?>
    
    								<li <?php post_class(); ?>><small style="font-size: 9px; color: #777;"><?php the_time('d/m/y'); ?></small> - <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    								<?php }
    							endif;
    							endforeach; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • keep the ‘new’ state for 24hrs:

    date('U') gets the ‘now’ time (in seconds from the beginning of a certain time)
    get_the_time('U') gets the time of the post;

    if the difference is less than 86400 ( 60 sec * 60 min * 24 hrs = 1 day) then do whatever:

    <?php $old = date('U') - get_the_time('U') ; if( $old < 86400 ){ echo 'new ';} ; ?>

    http://codex.wordpress.org/Function_Reference/get_the_time

    or by date: date('z') gets the day of the year; (this would keep the ‘new’ state for at least a full day, but up to 47.9 hrs. i.e. everything posted on the 26.march would stay ‘new’ to the end of 27.march)

    <?php $old = date('z') - get_the_time('z') ; if( ( date('Y') == get_the_time('Y')) && ( $old <= 1 ) ) { echo 'new ';} ; ?>
    hope this helps.

    Thread Starter monkhouse

    (@monkhouse)

    thanks for the help but it did not work.

    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?><br />
    							<li <?php post_class(); ?>><small style="font-size: 9px; color: #0000FF;"><?php $old = date('U') - get_the_time('U') ; if( $old < 86400 ){ echo 'new ';} ; the_time('d/m/y'); ?></small> - <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    						</ul><br />

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add new in title’ is closed to new replies.