The following column WordPress Tutorial will introduce to you how to solve the problem of upgrading WordPress to add special styles to articles published within a certain period of time. I hope it will help you if you need Friends help!
Through the following code, you can add a "latest article" prompt or output different styles for articles published within a certain period of time, and add them to the main loop of the theme template.
Add special styles to articles published within a certain period of time
Code 1
<?php $t1 = $post->post_date; $t2 = date( "Y-m-d H:i:s" ); $t3 = '24'; $period = ( strtotime( $t2 )-strtotime( $t1 ) )/3600; if ( $period < $t3 ) { ?> 一天之内 <?php } else { ?> 一天之外 <?php } ?>
$t3 = '24', which is limited to 24 Within hours, modify the number to adjust the time.
Code 2
<?php $period = current_time('timestamp') - get_the_time('U'); if ( $period <= 86400 ) { ?> 一天之内 <?php } else { ?> 一天之外 <?php } ?>
Modify 86400 seconds and adjust the time limit.
The above is the detailed content of How to add special styles to articles published within a certain period of time in WordPress. For more information, please follow other related articles on the PHP Chinese website!