Home > CMS Tutorial > WordPress > 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

藏色散人
Release: 2020-11-27 15:57:15
forward
9333 people have browsed it

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 } ?>
Copy after login

$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 } ?>
Copy after login

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!

Related labels:
source:zmingcx.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template