当网站搭建成功后,我们如果想更进一步,那就必须无尽的折腾,这样才有意思。今天在论坛发帖的时候,发现每当更新一篇文章时,都会在帖子标题后面多出一个最新图标。既然论坛能实现,wordpress应该也可以做到吧,随便一搜,尽然搜出一箩筐,经过测试修改验证后,以下代码屡试不爽,借此篇文章测试下,如果你也想实现这样的效果,刚好按照以下步骤操作即可。
1、打开首页文件index.php,找到以下代码:
- <?php the_title(”); ?>
或者:
- <a href=“<?php the_permalink() ?>”><?php the_title_attribute(); ?></a>
2、在其后添加一段函数代码:
- <?php
- $t1=$post->post_date;
- $t2=date(“Y-m-d H:i:s”);
- $diff=(strtotime($t2)-strtotime($t1))/3600;
- if($diff<24){echo ‘<img src=“‘.get_bloginfo(‘template_directory’).’/images/new.gif“ />’;}
- ?>
注意:粉色部分为图片路径,按照自己的图片存放位置修改正确!
3、下载NEW图标上传至主题文件夹中,以下是小川搜集的图标资源,可以按需求选择使用:
怎么在后台首页文件index.php中找不到<?php the_title(
怎么在后台首页文件index.php中找不到<?php the_title(
怎么在后台首页文件index.php中找不到<?php the_title(
怎么在后台首页文件index.php中找不到<?php the_title(”); ?> 或<?php the_title_attribute(); ?> 代码啊!!!
❗ 🙁 🙂
小川老师,我来支持下您哦!!!感谢分享
谢谢!