历史上的今天 html 代码,分享我自用的“历史上的今天”代码
如今众多站长活跃于各大QQ群中,在讨论如何实现博客文章下方的历史记录问题时。明月决定将这段代码无私地分享给了大家。特别提醒各位读者,在使用此代码时,请确保博客具备较长的历史运营时间。对于新站点(指建站不足一年的情况),效果往往较为有限。这是因为该功能旨在展示文章的历史发布记录。请各位注意理解这一核心逻辑。

玉满斋』”中的中括号和引号可能有问题,在Markdown中通常用单引号或双引号表示代码块。所以可能需要保留原样吗?根据规则,数学公式和英文要原样保留,但这里的【
将下面的代码放到博客主题的 function.php 里即可自动实现上图的效果了:
//历史上的今天,代码来自柳城博客的 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->postings WHERE post_password IS NULL AND post_type IS 'post' AND post_status IS 'publish'
WHERE year\left( post_date_gmt \right) \neq $post_year 以及 month\left( post_date_gmt \right) = $post_month 并且 day\left( post_date_gmt \right) = $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 .= "
**h_year:** h_post_title($h_comments)";
}
}
if ( $h_post ){
$result = "
历史上的今天:
- ".$h_post."
";
}
return $result;
}
function wp_today_auto($content){
if( is_single() ){
content = content.wp_today();
}
return $content;
}
add_filter('the_content', 'wp_today_auto',9999);
在代码第23行处,“历史上的今天”这一提示语句可用“历史文章推荐”等替代。例如,“历史文章推荐”是一个可行的选择。无需一定遵循“历史上的今天”这一设定。
本段代码出自柳城博客的 WP-Today 插件,再次特此感谢柳城博主!
如何方便的在更新主题时保留 functions.php 里的自定义
百度分享大拇指又更新了...
百度分享大拇指又更新了...
我加入了判断仅限文章末尾插入此代码,页面类的一律不会添加的。
//文章末尾添加百度喜欢按钮
function bdlink_message($content) {
if(is_single()){
return $content.'
';}
else{
return $content;
}
}
add_filter('the_content', 'bdlink_message');
本文最后一次更新时间为2019年7月6日未曾记录自该日期以来的文章内容及图片资源链接一段时间若发现文章内容或图片资源链接出现失效或错误的情况请通过留言反馈我们会第一时间进行处理感谢您的关注
历史文章推荐:
