为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标签

9 Comments

  1. Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you can do with some pics to drive the message home a little bit, but instead of that, this is magnificent blog. An excellent read. I will certainly be back.

  2. Normally I do not learn article on blogs, however I would like to say that this write-up very forced me to take a look at and do so! Your writing taste has been amazed me. Thank you, quite great post.

  3. I am not certain the place you are getting your info, but great topic. I must spend a while finding out much more or working out more. Thank you for fantastic information I was looking for this info for my mission.

  4. My brother suggested I might like this blog. He was entirely right. This post truly made my day. You can not imagine just how much time I had spent for this info! Thanks!

  5. I am not positive the place you’re getting your information, but good topic. I needs to spend some time learning much more or working out more. Thanks for magnificent info I was searching for this info for my mission.

  6. I cling on to listening to the reports lecture about getting boundless online grant applications so I have been looking around for the finest site to get one. Could you advise me please, where could i acquire some?

  7. Hello.This post was extremely fascinating, especially since I was browsing for thoughts on this topic last Saturday.

  8. Great post. I was checking continuously this blog and I’m impressed! Extremely useful information particularly the last part 🙂 I care for such info much. I was seeking this particular info for a very long time. Thank you and best of luck.

Comments are closed.