为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. Thank you, I have just been searching for info approximately this topic for a while and yours is the best I have found out till now. But, what in regards to the conclusion? Are you certain concerning the supply?

  2. Very interesting info !Perfect just what I was searching for! “It’s not the having, its the getting.” by Elizabeth Taylor.

  3. Pretty nice post. I just stumbled upon your blog and wanted to say that I have truly enjoyed surfing around your blog posts. After all I’ll be subscribing to your feed and I hope you write again very soon!

  4. I wish to get across my admiration for your kind-heartedness supporting those individuals that really want assistance with this content. Your real commitment to passing the solution up and down was unbelievably productive and have consistently allowed girls just like me to achieve their aims. This warm and friendly guide indicates this much to me and especially to my mates. Thanks a lot; from all of us.

  5. Very good written post. It will be supportive to everyone who utilizes it, as well as myself. Keep up the good work – looking forward to more posts.

  6. I and my friends have been checking the good key points on your site and then at once got an awful suspicion I had not expressed respect to the site owner for those techniques. Most of the women came totally passionate to read them and already have quite simply been taking advantage of them. Many thanks for turning out to be really kind and also for making a choice on varieties of useful subject matter most people are really desirous to discover. My sincere regret for not expressing gratitude to you earlier.

  7. I have read a few excellent stuff here. Certainly value bookmarking for revisiting. I wonder how so much attempt you set to make any such great informative website.

Comments are closed.