get_results(
"SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month, COUNT(*) AS count
FROM {$wpdb->posts}
WHERE post_type = 'post' AND post_status = 'publish'
GROUP BY YEAR(post_date), MONTH(post_date)
ORDER BY year DESC, month DESC"
); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
if (empty($rows)) {
echo '
'
. esc_html__('暂无文章。', 'aksrt') . '
';
return;
}
$current_year = 0;
$shown = 0;
?>
year !== $current_year) :
$current_year = (int) $row->year;
?>
month, (int) $row->count)); ?>
(int) $row->year,
'monthnum' => (int) $row->month,
'posts_per_page' => -1,
'post_status' => 'publish',
'no_found_rows' => true,
]);
foreach ($month_posts as $mp) :
if ($limit > 0 && $shown >= $limit) {
break;
}
$shown++;
?>
-
0 && $shown >= $limit) { break; } ?>