wordpress统计每日发布文章数量插件
事情是这样的,我昨天突发奇想,想知道自己每天发了多少文章,网上找插件也没找到,索性自己利用ai写了个插件。功能比较简单,效果如下:源代码:
<?php
/*
Plugin Name: 文章发布数量统计
Plugin URI:
Description: 用来统计每日发布文章数量。
Version: 1.0
Author: tien
Author URI:
*/
function get_daily_post_counts($start_date, $end_date) {
global $wpdb;
$query = $wpdb->prepare("
SELECT DATE(post_date) AS post_date, COUNT(*) AS post_count
FROM $wpdb->posts
WHERE post_status='publish' AND post_date BETWEEN %s AND %s
GROUP BY DATE(post_date)
ORDER BY post_date ASC
", $start_date, $end_date);
return $wpdb->get_results($query);
}
function render_date_range_buttons() {
$base_url = remove_query_arg(array('start_date', 'end_date'));
$buttons = array(
'Last Week' => array(date('Y-m-d', strtotime('-1 week')), date('Y-m-d')),
'Last Month' => array(date('Y-m-d', strtotime('-1 month')), date('Y-m-d')),
);
echo '<div style="text-align: right; margin-bottom: 20px;">';
foreach ($buttons as $label => $dates) {
$url = add_query_arg(array('start_date' => $dates, 'end_date' => $dates), $base_url);
echo '<a href="' . esc_url($url) . '" class="button">' . esc_html($label) . '</a> ';
}
// Custom date range form
echo '
<form method="get" style="display: inline;">
<input type="hidden" name="page" value="post-stats">
<input type="date" name="start_date">
<input type="date" name="end_date">
<input type="submit" value="Go" class="button">
</form>';
echo '</div>';
}
function render_post_stats_page() {
$start_date = isset($_GET['start_date']) ? $_GET['start_date'] : date('Y-m-d', strtotime('-1 month'));
$end_date = isset($_GET['end_date']) ? $_GET['end_date'] : date('Y-m-d');
render_date_range_buttons();
$post_counts = get_daily_post_counts($start_date, $end_date);
// Convert the data to the format required by Chart.js
$labels = array();
$data = array();
foreach ($post_counts as $post_count) {
$labels[] = $post_count->post_date;
$data[] = $post_count->post_count;
}
// Output the chart container
echo '<canvas id="postStatsChart"></canvas>';
// Output the chart script
echo '
<script>
var ctx = document.getElementById("postStatsChart").getContext("2d");
var myChart = new Chart(ctx, {
type: "bar",
data: {
labels: ' . json_encode($labels) . ',
datasets: [{
label: "Post Count",
data: ' . json_encode($data) . ',
backgroundColor: "rgba(75, 192, 192, 0.2)",
borderColor: "rgba(75, 192, 192, 1)",
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
},
plugins: {
datalabels: {
display: true,
color: "black",
align: "start",
anchor: "end",
offset: -20,
formatter: function(value, context) {
return value;
}
}
}
}
});
</script>
';
}
function post_stats_menu() {
add_menu_page('Post Stats', 'Post Stats', 'manage_options', 'post-stats', 'render_post_stats_page');
}
function post_stats_scripts() {
wp_enqueue_script('chartjs', 'https://cdn.jsdelivr.net/npm/chart.js@2.9.4');
wp_enqueue_script('chartjs-datalabels', 'https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@0.7.0');
}
add_action('admin_menu', 'post_stats_menu');
add_action('admin_enqueue_scripts', 'post_stats_scripts');
?>
成品:https://www.123pan.com/s/TKR5Vv-xIO5v.html 大佬你好我1天就发一篇 有时候是0篇从来没有这样的烦恼! 庄生晓梦2021 发表于 2023-8-3 20:20
大佬你好我1天就发一篇 有时候是0篇从来没有这样的烦恼!
你还真是个人才:lol
佩服佩服,下载试试 一天发这么多是怎么发的呢 大佬有没有 在文中某个字节后添加关键词的插件。 不想知道你是咋统计的,只想知道你是咋发的这么多? 采集的数据吗 哎哟还是不会 发表于 2023-8-4 08:35
大佬有没有 在文中某个字节后添加关键词的插件。
你说的这个用sql命令应该可以吧
页:
[1]
2