文章最后更新时间:

代码
func.php中加入
<?php
// functions.php
if (!function_exists('get_posts_count_today')) {
function get_posts_count_today($post_type = 'post') {
$today = date('Y-m-d');
$args = array(
'post_type' => $post_type,
'post_status' => 'publish',
'date_query' => array(
array(
'after' => $today . ' 00:00:00',
'before' => $today . ' 23:59:59',
'inclusive' => true,
),
),
'fields' => 'ids',
'nopaging' => true,
);
$query = new WP_Query($args);
return $query->post_count;
}
}
// functions.php
add_action('wp_footer', 'output_site_stats_js_vars');
function output_site_stats_js_vars() {
// 获取数据
$count_posts = wp_count_posts();
$published_posts = $count_posts->publish;
$today_posts = function_exists('get_posts_count_today') ? get_posts_count_today() : 0;
$uptime_days = floor((time() - strtotime("2023-11-11 11:11:11")) / 86400);
global $wpdb;
$users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");
$comments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
$post_view = function_exists('nd_get_all_view') ? nd_get_all_view() : get_option('zibi_pageviews_total', 0);
// 输出 JS 变量
echo '<script type="text/javascript">
var tj_wzzs = "' . esc_js($published_posts) . '";
var tj_jrgx = "' . esc_js($today_posts) . '";
var tj_yxsj = "' . esc_js($uptime_days) . '";
var tj_yhzs = "' . esc_js($users) . '";
var tj_plzs = "' . esc_js($comments) . '";
var tj_zll = "' . esc_js($post_view) . '";
</script>';
}
自定义HTML小工具随便放在合适的地方
© 版权声明
© 版权声明 All Rights Reserved
THE END







暂无评论内容