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
- stsdust 杭州联通大带宽 nat 预售二期,便宜国内大带宽 nat全球[VPS测评]
- 搬瓦工 CN2 GIA 补货啦,10Gbps 超大带宽美国 CN2 GI美国VPS[主机]
- cloudcone→超大硬盘 VPS 补货 洛杉矶 KVM 最高 500全球[VPS测评]
- raksmart 日本 cn2+软银服务器带宽速度及综合性能测评,rak日本VPS[主机]
- SmartHost→$6.95 月 KVM-1GB 内存 1TB 硬盘 全球[VPS测评]
- 搬瓦工 CN2 GIA 补货啦,10Gbps 超大带宽美国 CN2 GI美国VPS[主机]
- [双十二]HostXen 充 300 送 50 续费减 10 元 买 2全球[VPS测评]
- WebUploader 设置只能上传单张图片全球[VPS测评]
- 便宜 VPS 3.5 刀每月 512M 内存 500G 流量 20G 全球[VPS测评]
- GigsGigsCloud 日本 VPS 上线 分为 CN2 和软银线路日本VPS[主机]
- 樊云→美国 cn2 VPS+免费 50G 防御+不限流量 40 元 月 美国VPS[主机]
- bootstrapTable 设置行样式(背景颜色)全球[VPS测评]
- WordPress 超高压缩率 支持webp图片格式的图片压缩插件:Sh全球[VPS测评]
- VPS 装什么系统网站快 Debian稳定首推全球[VPS测评]
- Veesp俄罗斯VPS春节特惠全场VPS和独立服务器新用户首次付款五折优独立服务器[U]
- TPE海缆故障通报-完成修复全球[VPS测评]
- OLVPS 德国 流媒体解锁 384M 内存 5G Nvme 256G单全球[VPS测评]
- 吸血鬼崛起服务器怎么快速搭建?全球[VPS测评]
- 云服务器能干什么?有几十种玩法?阿里云,腾讯云服务器如何购买?全球[VPS测评]
- VPSPlayer,超便宜香港cn2线路小带宽VPS,2核4G内存仅30香港VPS[主机]
- 菜单选中标记CSS3动画效果全球[VPS测评]
- 1分钟快速读懂云计算全球[VPS测评]
- 恒创主机优惠码85折_服务器优惠券8折_恒创科技优惠_代金券全球[VPS测评]
- tudcloud:香港vps/2核/2GB/20GB空间/不限流量/KV虚拟空间(主机)
- 金斗云怎么样?香港CN2月付23元,圣何塞CN2月付22元香港VPS[主机]
- 樊云:9折优惠,香港cn2 vps+(强制三网、50G高防);美国cn2美国VPS[主机]
- UCloud优刻得云服务器建站教程:香港云服务器购买优惠方法香港VPS[主机]
- 糖果主机(sugarhosts):春季优惠,云服务器/云vps/虚拟主机全球[VPS测评]
- wikihost,微基主机服务,100M带宽香港tudcloud,5G防香港VPS[主机]
- 创e云:香港CN2VPS优惠专区,4核/4G/20G/2Mbps不限流量香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-39943.html











