Last update at :2023-12-31,Edit by888u
Many wordpress themes have integrated the "NEW" mark for newly added articles. Some people like this and some don't. If the wordpress theme you use does not have such a function, you can still add it yourself. The advantage is that regular visitors can find the latest content of the website at a glance, hehe. Here, this site has collected the latest tips for everyone, and the method is very simple. All we need to do is put the code provided below where you want it to be displayed, such as after the article title of the homepage list (mostly in the middle of
), or in the gadget article list, etc. You need to add it to the corresponding file.Text prompt code
The simplest way is to directly output an English word NEW
- $t1=$post->post_date;
- $t2=date(“Y-m-d H:i:s”);
- $diff=(strtotime($t2)-strtotime($t1))/3600;
- if($diff<24){echo “New”;} //The number is the number of hours to judge the output NEW, please modify it according to your own situation
- else{echo "";} //No content will be output if the time exceeds
- ?>
Picture version prompt code
To make it more beautiful, we can make a separate reminder image.
- $t1=$post->post_date;
- $t2=date(“Y-m-d H:i:s”);
- $diff=(strtotime($t2)-strtotime($t1))/3600;
- if($diff<24){echo "
";} //The number is the number of hours to judge the output NEW, please modify it according to your own situation li>
- else{echo "";} //No content will be output if the time exceeds
- ?>
Beautified version
Compared with the image version, which directly outputs images, I chose to set the prompt image in CSS, which can better control the display position of the prompt image and match the corresponding image to achieve better visual effects. In the upper right corner of the title, there is a suitable subtitle without any sense of violation.
html code, placed in front of the home page article list title
- $t1=$post->post_date;
- $t2=date(“Y-m-d H:i:s”);
- $diff=(strtotime($t2)-strtotime($t1))/3600;
- if($diff<24){echo "";} //The number is to determine the number of hours to output NEW, please base it on your own situation Modify
- else{echo "";} //No content will be output if the time exceeds
- ?>
The css code is written into style.css
- .new–post {
- background: url(img/new.png) no–repeat;
- position: absolute;
- width: 44px;
- height: 45px;
- right: –3px;
- top: –3px;
- z–index: 10;
- }
Please back up the file when modifying it to prevent timely recovery in the event of an error. In fact, most of the time you just mess around on your own, so take your time! In addition, it does not mean that the website must add these small functions. The more functions, the more resources it takes up. A host with too many restrictions may cause various problems, so please choose reasonably according to your own needs.
Recommended site searches: Telecom IP proxy, US virtual space, domain name registration service website, Wanwang space, permanent free cloud server address, free international domain name registration space, dynamic IP dialer, US host network, US multi-IP station group vps,
发表评论