为wordpress文章填加上new或top标签

完全不是这网页设计专业的,这些天弄wordpress,终于搞定了这件事情,发文备案,以免以后忘记,也可以给大家提供点设置技巧。

原理很简单,即是使用了if函数和echo返回标识

一、填加TOP标识

<?php if ( is_sticky() ) {echo "<span style='color:red;'><i>Top</i></span>";}?>

即,如是这是置顶文章,那么返回文字Top,也可以返回图片:

<?php if ( is_sticky() ) {echo "<img src=logo.jpg>";}?>

将图片地址换成你的地址即可

将代码填加在下面代码的后面

<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>

二、填加New标识

<?php

$t1=$post->post_date;

$t2=date("Y-m-d H:i:s");

$diff=(strtotime($t2)-strtotime($t1))/3600;
if($diff<24){echo "<span style='color:red;'><i>New</i></span>";}

?>

我这里将时间设成了24小时,你也可以设置成任意时间,是以你的发布时间为准的,返回图片和加Top标识一样

三、注意事项

<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>

这段代码很多地方有,我是填加在blog-layout-1.php文件当中,因为我只需要在首页中体现,而我的首页是选择index下的blog-layout-1模版,如果你需要在其他模版中体现,那么需要填加到对应的模版当中。难度不大,但是对于我这种完全没有学过Php代码的人,也是摸了很久才学会的,希望对大家有所帮助

原创文章,转载请注明: 转载自飞月秀

本文链接地址: 为wordpress文章填加上new或top标签

8 Comments

  1. You are my inspiration , I have few blogs and very sporadically run out from to brand.I believe this site holds some very good info for everyone. “A sense of share is not a bad moral compass.” by Colin.

  2. I like what you guys are up too. Such clever work and reporting! Carry on the superb works guys I¡¦ve incorporated you guys to my blogroll. I think it’ll improve the value of my site 🙂

  3. I was suggested this blog by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my trouble. You’re incredible! Thanks!

  4. Hi my loved one! I wish to say that this article is awesome, great written and include almost all vital infos. I would like to peer more posts like this .

  5. Excellent read, I just passed this onto a colleague who was doing some research on that. And he just bought me lunch because I found it for him smile Therefore let me rephrase that: Thanks for lunch!

  6. hello there and thank you for your information – I have definitely picked up something new from right here. I did however expertise a few technical points using this site, as I experienced to reload the website lots of times previous to I could get it to load correctly. I had been wondering if your hosting is OK? Not that I am complaining, but slow loading instances times will sometimes affect your placement in google and can damage your quality score if advertising and marketing with Adwords. Well I’m adding this RSS to my e-mail and can look out for much more of your respective intriguing content. Make sure you update this again soon..

  7. I take pleasure in, result in I discovered exactly what I used to be looking for. You’ve ended my four day lengthy hunt! God Bless you man. Have a nice day. Bye

  8. Hello there, You have done an excellent job. I will definitely digg it and personally recommend to my friends. I am sure they’ll be benefited from this website.

Comments are closed.