WordPress实现\”历史上的今天\”文章调用方法
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

如果我们有在使用WordPress搭建个人博客的时候,一般很多网友都喜欢自己捣鼓各种功能。比如我们会自定义调用随机内容、热门文章帖子等信息。WordPress有些功能是自带的,有些是需要我们用插件和代码脚本实现的。蜗牛在浏览网友博客的时候会看到有些博主在文章篇幅底部设置历史上的今天调出文章,这样还有比较有意思的,可以看到去年、前年的今天更新过哪些文章。
这个功能如何实现的呢?其实可以通过This Day In History插件实现,直接在后台搜索安装即可去设置调用。我们也可以使用无插件只用代码实现。
第一、脚本部分
//历史上的今天,代码来自柳城博主的WP-Today插件
function wp_today(){
global $wpdb;
$post_year = get_the_time(\’Y\’);
$post_month = get_the_time(\’m\’);
$post_day = get_the_time(\’j\’);
$sql = \”select ID, year(post_date_gmt) as h_year, post_title, comment_count FROM
$wpdb->posts WHERE post_password = \’\’ AND post_type = \’post\’ AND post_status = \’publish\’
AND year(post_date_gmt)!=\’$post_year\’ AND month(post_date_gmt)=\’$post_month\’ AND day(post_date_gmt)=\’$post_day\’
order by post_date_gmt DESC limit 5\”;
$histtory_post = $wpdb->get_results($sql);
if( $histtory_post ){
foreach( $histtory_post as $post ){
$h_year = $post->h_year;
$h_post_title = $post->post_title;
$h_permalink = get_permalink( $post->ID );
$h_comments = $post->comment_count;
$h_post .= \”<li><strong>$h_year:</strong> <a h=\’\”.$h_permalink.\”\’ title=\’\”.$h_post_title.\”\’ target=\’_blank\’>$h_post_title($h_comments)</a></li>\”;
}
}
if ( $h_post ){
$result = \”<h2>历史上的今天:</h2><ul>\”.$h_post.\”</ul>\”;
}
return $result;
}
function wp_today_auto($content){
if( is_single() ){
$content = $content.wp_today();
}
return $content;
}
add_filter(\’the_content\’, \’wp_today_auto\’,9999);
将代码加入到当前主题的Functions.php文件中。
第二、调出历史文章
<?php echo wp_today(); ?>
在需要调出历史今天的位置加上上面调出代码。对于CSS样式我们自行设置添加。
[WordPress插件]历史优惠活动内容
猜你可能想看的VPS
- CN2 GIA $12.5 年 256M 内存 10G SSD 0.5T全球[VPS测评]
- Fresh Roasted Hosting→$30 月 I3-540 8全球[VPS测评]
- ThinkPHP5 动态创建数据表方法全球[VPS测评]
- 大流量 VPS $4 月 512M 内存 20G SSD 10TB 流量全球[VPS测评]
- 2019 阿里云双 11 活动→云服务器 86 元 年 2 核 4G 内全球[VPS测评]
- 有点绕-Cloudean→€10 月 2GB 内存 30GB SSD 空虚拟空间(主机)
- 企鹅小屋→99 元 年 1GB 内存 10GB SSD 空间 200GB虚拟空间(主机)
- imidc→e3 e5 独服 120 台 $30 月 香港服务器 台湾服日本VPS[主机]
- TmhHost→洛杉矶 Cera 洛杉矶安畅(CN2 GIA)九折 月付全球[VPS测评]
- Aurora→日本 CN2 GIA 线路 KDDI 线路 可以解锁 ne日本VPS[主机]
- CN2 GIA VPS 和商家推荐全球[VPS测评]
- LOCVPS→38.5 元 月 XEN-2GB 40GB 3M 香港机房香港VPS[主机]
- 不要再相信这4个错误的Google 搜索引擎SEO优化观念全球[VPS测评]
- WordPress站内链接修改插件:Velvet Blues Updat全球[VPS测评]
- SoftShellWeb 黑五促销 中国台湾大陆优化线路 1g内存 带5全球[VPS测评]
- HostMayo便宜vps全场五折,可选洛杉矶和荷兰机房,512m内存特全球[VPS测评]
- 宝塔面板怎么放行端口?宝塔面板放行端口的方法全球[VPS测评]
- 又有美议员窜访台,中国驻美大使馆:“中方将对美国的挑衅采取果断的反制措施美国VPS[主机]
- edgenat:韩国cn2+香港cn2,VPS八折优惠,8核8G/50gWINDOWS
- 阳帝云:香港大宽带vps仅15元/月;美国vps200G防御仅28元/月美国VPS[主机]
- 虾皮跨境电商怎么样?虾皮跨境电商靠谱吗?全球[VPS测评]
- diyvm:香港vps/美国vps/日本vps/2核/2G内存/5M带宽日本VPS[主机]
- 跨境电商平台首选香港服务器香港VPS[主机]
- 恒创科技:国庆中秋双节同庆,香港1核2G云服务器,年付378元香港VPS[主机]
- 奇异互动,2核4G香港云服务器仅655元/年,注册领550元新手大礼包香港VPS[主机]
- 40火伞高压电爬坡更让企业用电于民全球[VPS测评]
- 者也vps年终特惠:全场云服务器7折终身优惠,赠1G内存,充1000送3全球[VPS测评]
- 极光KVM:新上香港CN2VPS,终身6折优惠,1核/1G/5Mbps,香港VPS[主机]
- 香港云服务器的优势有哪些方面香港VPS[主机]
- DMIT:香港CN2 GIA VPS,1核/750M内存/10G硬盘/4香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-39943.html











