要解决这个问题,您需要在functions.php文件中添加以下代码:
add_filter( 'get_archives_link', 'exclude_last_archive_link' );
function exclude_last_archive_link( $link ) {
global $wpdb;
$archives = $wpdb->get_results("
SELECT YEAR(post_date) AS year
, MONTH(post_date) AS month
, count(ID) as posts
FROM $wpdb->posts
WHERE post_type = 'post' AND post_status = 'publish'
GROUP BY YEAR(post_date), MONTH(post_date)
ORDER BY post_date DESC
");
$last_archive = '';
if (count($archives)) {
$last_archive_year_month = reset( $archives );
$last_archive = '&m=' . $last_archive_year_month->year . sprintf( '%02d', $last_archive_year_month->month);
}
if (!empty($last_archive) && strpos($link, $last_archive) !== false) {
return '';
}
return $link;
}
此代码将在归档页面上排除最后一篇文章链接,并确保其他归档链接显示在页面上。
上一篇:不在gitlog中显示pgp签名
下一篇:不在滚动视图中滚动