Home  >  Article  >  CMS Tutorial  >  How to add special styles to articles published within a certain period of time in WordPress

How to add special styles to articles published within a certain period of time in WordPress

藏色散人
藏色散人forward
2020-11-27 15:57:159233browse

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!

How to add special styles to articles published within a certain period of time in WordPress

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 = &#39;24&#39;;
$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(&#39;timestamp&#39;) - get_the_time(&#39;U&#39;);
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!

Statement:
This article is reproduced at:zmingcx.com. If there is any infringement, please contact admin@php.cn delete