如何给发表一定时间内文章添加特殊样式?

无评论

作者照片

By 霜天

如何给发表一定时间内文章添加特殊样式?通过下面的代码,可以为一定时内发表的文章添加“最新文章”提示或者输出不同的样式,加到主题模板主循环中。

代码一

<?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\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,为限定24小时内,修改数字调整时间。

代码二

<?php

$period = current_time(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’timestamp\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’) – get_the_time(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’U\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’);

if ( $period <= 86400 ) { ?>

一天之内

<?php } else { ?>

一天之外

<?php } ?>

修改其中的86400秒,调整时间限定。

发表评论