如何在特定时间内在Wordpress的主页上显示帖子?
例如,如果Wordpress安装的时间在8-10 is之间,如何显示帖子
发布于 2014-04-01 22:01:25
您可以使用WP current_time()和PHP date()的组合。并向主题的functions.php文件添加一个函数:
function is_time_to_show_post()
{
$now = current_time( 'timestamp' );
$hour_now = date( 'H', $now ); // 24h format
if( $hour_now >=20 && $hour_now <= 22 )
return true;
return false;
}在您的模板(index.php、search.php等)中:
<?php
if( is_time_to_show_post() ) {
echo 'Your post';
}
?>确保在http://exmaple.com/wp-admin/options-general.php中设置正确的格林尼治标准时间。
https://stackoverflow.com/questions/22784743
复制相似问题