最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - Wordpress Recent Post with the badge “New” on the side of the title post

programmeradmin4浏览0评论

Blog Page: Single Post:

I'd like to greet everyone a Happy New Year and Happy Holidays. I have a request on how to put a label "New" beside the title post on my recent post and my single recent post(red Mark in the photo). I keep on finding for answers on the internet for days and I couldn't find one. I hope you guys give an idea, demo or answers on this particular wordpress subject this would give me a big help and I hope I didn't bother anyone on celebrating your holiday. Thank you.

Blog Page: Single Post:

I'd like to greet everyone a Happy New Year and Happy Holidays. I have a request on how to put a label "New" beside the title post on my recent post and my single recent post(red Mark in the photo). I keep on finding for answers on the internet for days and I couldn't find one. I hope you guys give an idea, demo or answers on this particular wordpress subject this would give me a big help and I hope I didn't bother anyone on celebrating your holiday. Thank you.

Share Improve this question edited Feb 9, 2020 at 12:51 jricc russel asked Dec 29, 2019 at 8:55 jricc russeljricc russel 11 bronze badge 1
  • This is something you'll probably want to add to your theme, both the archive page (for the top one?) and the single post page for the bottom one. Whatever your logic for 'new' you can then output the 'new' text / icon next to the date. Can you find the relevant bits in your theme? If it's a third-party theme you might want to make a child theme to do the actual extending so that you don't lose your changes when the source theme updates. – Rup Commented Dec 29, 2019 at 12:34
Add a comment  | 

1 Answer 1

Reset to default 0

This should get you started. It checks if the post was posted less than a day ago, and if it was, it will display a label that says new, which you can style.

<?php if(get_the_date('Y-m-d-H-i-s') > date("Y-m-d-H-i-s",strtotime("-1 day"))) { ?>
<span class="new-label">New</span>
<?php } ?>

You need to add this to your theme, in the file that displays posts.

发布评论

评论列表(0)

  1. 暂无评论