为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. You actually make it seem so easy with your presentation but I find this topic to be really something which I think I would never understand. It seems too complicated and very broad for me. I’m looking forward for your next post, I will try to get the hang of it!

  2. Thanks a lot for sharing this with all folks you actually understand what you’re talking about! Bookmarked. Please additionally visit my website =). We will have a link change arrangement among us!

  3. Thank you for the sensible critique. Me and my neighbor were just preparing to do a little research on this. We got a grab a book from our area library but I think I learned more from this post. I’m very glad to see such magnificent information being shared freely out there.

  4. I have been browsing online more than three hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. Personally, if all site owners and bloggers made good content as you did, the net will be a lot more useful than ever before.

  5. I used to have a pop-up message when i start firefox to restore last session but now it’s gone. I need it in case i accidentally close something and i want to go back into it. Anybody know how to do it? Thanks..

  6. I simply want to tell you that I am all new to blogging and site-building and seriously enjoyed this web page. Likely I’m likely to bookmark your blog . You really have impressive well written articles. Regards for sharing with us your website page.

Comments are closed.