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
- 疯狂猜成语 图猜成语日历上三个日子是太阳剩下的都是冰块是什么成语?全球[VPS测评]
- MyW→洛杉矶 德国分销主机 50GB SSD 空间 不限域名 年付 4虚拟空间(主机)
- ¥34 月 2G 内存 30G SSD 2Mbps 不限量 Xen 香港香港VPS[主机]
- PacificRack→$9.99 年 KVM-1GB 13GB 2TB全球[VPS测评]
- select2 动态设置选中项全球[VPS测评]
- jquery 禁用 select 以及取消禁用的方法全球[VPS测评]
- 双十一 嘟牛云→香港机房套餐尊享 75 折优惠 免费内存翻倍 充值返额 香港VPS[主机]
- TripodCloud→圣何塞 CN2 GIA 线路 KVM 年付 38全球[VPS测评]
- Moack 韩国独立服务器特惠,2.5 折起,双路 E5 32G 内存 独立服务器[U]
- 真实测评 云创网络→1 核 1G 内存 20G 硬盘特价套餐测评数据全球[VPS测评]
- 优惠 SparkVPS→$69 年资源池 VPS 8 核 8G 120G全球[VPS测评]
- 傲游主机开学季全场 75 折 香港&韩国&美国 VPS 月付 52 元起日本VPS[主机]
- servarica →$12 年 加拿大 VPS 原生 IP 1G 内存全球[VPS测评]
- 哪些WordPress收费主题最靠谱?全球[VPS测评]
- 什么是蜘蛛黑洞及如何避免全球[VPS测评]
- 新博客如何快速通过 Google AdSense 账号申请全球[VPS测评]
- HostoWeb → 8.5$ 月 摩洛哥 1核256Mb内存10G硬盘全球[VPS测评]
- 自适应bootstrap左侧导航可关闭全球[VPS测评]
- VPS到底有什么用?全球[VPS测评]
- 快速云:vps云服务器的区别是什么?2022-08-1913:32来源:全球[VPS测评]
- 云计算到底是谁发明的?全球[VPS测评]
- wikihost,微基主机:1核/1G/15G/100Mbps/香港vp香港VPS[主机]
- 曾经最大跨境电商平台团队收缩,只剩20人丨GoingGlobal周报全球[VPS测评]
- jquery css3实现的进度条动画特效,带加载进度条百分比动态效果。全球[VPS测评]
- 拼多多入局跨境电商平台,首站美国;奈雪的茶在上海建第二总部;pidan“美国VPS[主机]
- 青果云:香港云主机2核1G3M30G,香港vps仅售59元/月香港VPS[主机]
- 极光KVM:美国香港vps CN2 GIA专线高速稳定,BGP服务器低至美国VPS[主机]
- 恒创科技:香港免备案CN2线路VPS/美国CN2直连VPS,月付28元起美国VPS[主机]
- 狸猫云:香港高速CN2VPS,200元/年-香港高速GIA云服务器促销活香港VPS[主机]
- 互盟云怎么样?1核2G云服务器仅468元/年,香港云主机58元/月香港VPS[主机]
转载请注明原文地址:https://www.motoll.com/read-39943.html