// 获取动态统计数据
$users_count = count_users()['total_users']; // 会员总数
$posts_count = wp_count_posts()->publish; // 已发布文章数
// 今日发布
$today = get_posts([
'date_query' => [
[
'year' => date('Y'),
'month' => date('m'),
'day' => date('d'),
],
],
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
]);
$today_count = count($today);
// 本周发布(周一到周日)
$week_start = new DateTime('monday this week');
$week_end = new DateTime('sunday this week');
$week_posts = get_posts([
'date_query' => [
[
'after' => $week_start->format('Y-m-d'),
'before' => $week_end->format('Y-m-d'),
'inclusive' => true,
],
],
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
]);
$week_count = count($week_posts);
// 网站运行天数(请将 '2011-05-18' 替换为你的真实上线日期)
$launch_date = '2011-05-18'; // ←←← 请修改为你网站实际上线日期!
$run_days = (new DateTime())->diff(new DateTime($launch_date))->days;
// 访问总数(兼容 WP-PostViews 插件)
$views_total = 0;
if (function_exists('get_meta_values')) {
// 尝试从 post_views_count 获取(WP-PostViews)
global $wpdb;
$views_total = $wpdb->get_var("SELECT SUM(meta_value+0) FROM {$wpdb->postmeta} WHERE meta_key = 'views'");
}
// 如果没有插件,可手动设置一个基础值或留空
if (!$views_total || $views_total < 0) {
$views_total = get_option('custom_site_views', 690330); // 可通过后台更新
}
?>
-
0+
访问总数
-
0+
会员总数
-
0+
文章总数
-
0+
今日发布
-
0+
本周发布
-
0+
运行天数
各类游戏源码从搭建到开服一站式解决!