效果同上,给新发布的文章(比如发布后24小时内)显示为 最新 图标,这样可以提醒访客。实现方法很简单,就是算个时间差,在规定时间内,插入特定文字或图标。
如果要显示热门文章标志Wordpress需要安装了wp-postviews或者非插件实现的postviews功能!
将以下代码放置在主循环中,多个置顶文章,也是放在主循环中:
<?php $postnew =''; $diff=(time()-strtotime($post->post_date))/3600; if(is_sticky()){ $postnew = 'sticky '; }elseif($diff<24){ $postnew = 'new '; }elseif(get_post_meta($post->ID, 'views', true) > 1000){ $postnew = 'hot '; } ?>
调用方法都是一样的,在你的文章最外层元素的class中添加<?php echo $postnew;?>
比如我的原来是
<div id="<?php $this->theID(); ?>">
添加后是
<div id="<?php $this->theID(); ?>">
如果你的标题是h1标签记得css里换成h1
.hot h2 a:after,.new h2 a:after,.sticky h2 a:after { content:"热门"; background-color:#ee0000; font-size:12px; color:#fff; font-weight:400; border-radius:2px; padding:0 2px; position:relative; top:-2px } .new h2 a:after { content:"最新"; background-color:#00CC00; } .sticky h2 a:after{ content:"置顶"; background-color:#FFBA00; }