{"id":232830,"date":"2023-01-28T13:16:00","date_gmt":"2023-01-28T10:16:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=232830"},"modified":"2023-02-02T16:29:03","modified_gmt":"2023-02-02T13:29:03","slug":"comment-afficher-les-statistiques-du-graphique-du-nombre-mensuel-de-messages-dans-wordpress","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/fr\/comment-afficher-les-statistiques-du-graphique-du-nombre-mensuel-de-messages-dans-wordpress\/","title":{"rendered":"Comment afficher les statistiques du graphique du nombre mensuel de messages dans WordPress ?"},"content":{"rendered":"<p>L&rsquo;URL\u00a0: <a href=\"https:\/\/helloacm.com\/archives-of-pagesposts\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">https:\/\/helloacm.com\/archives-of-pagesposts\/<\/a> affiche la liste des publications historiques et j&rsquo;ai ajout\u00e9 un joli chiffre suivant qui trace le nombre de publications pour chaque mois.<\/p>\n<p>graphique-messages-par-mois-wordpress-php-js<\/p>\n<p>Vous pouvez voir une activit\u00e9 difficile au cours des 12 derniers mois. Oui, nous devenons paresseux tout au long de l&rsquo;ann\u00e9e. <a href=\"https:\/\/wordpress.mediadoma.com\/fr\/comment-creer-une-page-darchives-resume-pour-tous-les-messages-pages-wordpress-en-utilisant-php\/\" title=\"Ce message\">Ce message<\/a> montre comment cr\u00e9er une telle page pour obtenir les messages, et le code suivant peut \u00eatre ajout\u00e9 dans la m\u00eame page pour tracer le graphique.<\/p>\n<p>Nous devons inclure une biblioth\u00e8que <a href=\"https:\/\/helloacm.com\/how-to-invoke-apis-the-javascriptajax-example\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">javascript<\/a> Chart tierce qui peut \u00eatre trouv\u00e9e \u00e0: <a href=\"https:\/\/helloacm.com\/js\/chart.js\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">https:\/\/helloacm.com\/js\/chart.js<\/a><\/p>\n<pre><code>\u00a0 echo '&lt;script language=\"Javascript\" src=\"&lt;a class=\"vglnk\" target=\"_blank\" href=\"https:\/\/helloacm.com\/js\/chart.js\" rel=\"nofollow\"&gt;&lt;span&gt;https&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;helloacm&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;js&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;chart&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;js&lt;\/span&gt;&lt;\/a&gt;\"&gt;&lt;\/script&gt;'.\"n\";\n\u00a0 global $wpdb; \/\/ &lt;a class=\"vglnk\" target=\"_blank\" href=\"http:\/\/helloacm.com\" rel=\"nofollow\"&gt;&lt;span&gt;helloacm&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;\/a&gt;\n\u00a0 \n\u00a0 \/\/ count the posts number group by each month\n\u00a0 $query = \"\n \u00a0 \u00a0 \u00a0select \n \u00a0 \u00a0 \u00a0 \u00a0concat(year(`post_date`), '-', month(`post_date`)) as `month`, \n \u00a0 \u00a0 \u00a0 \u00a0count(1) as `cnt` \n \u00a0 \u00a0 \u00a0from \n \u00a0 \u00a0 \u00a0 \u00a0`wp_posts` \n \u00a0 \u00a0 \u00a0where \n \u00a0 \u00a0 \u00a0 \u00a0(post_type='page' or post_type='post') and \n \u00a0 \u00a0 \u00a0 \u00a0`post_status` = 'publish' \n \u00a0 \u00a0 \u00a0group by \n \u00a0 \u00a0 \u00a0 \u00a0`month` \n \u00a0 \u00a0 \u00a0order by \n \u00a0 \u00a0 \u00a0 \u00a0`post_date` desc\n \u00a0 \u00a0 \u00a0limit\n \u00a0 \u00a0 \u00a0 \u00a0 12\n\"; \u00a0\/\/ change this to include more months. the default is 12 months in the past.\n\u00a0 \u00a0 \u00a0 \n\u00a0 $result = array_reverse($wpdb-&gt;get_results($query));\/\/ reverse the data to get a normal logic flow\n\u00a0 if ($result) {\n?&gt;\n\u00a0\n&lt;div id='ReportBarChartContainerMonthly'&gt;\n\u00a0 \u00a0 &lt;div id='ReportBarChartComponentMonthly' style='margin: 15px;'&gt;\n\u00a0 \u00a0 \u00a0 \u00a0 &lt;canvas id=\"myChartMonthly\" style='max-width:100%;height:auto'&gt;&lt;\/canvas&gt;\n\u00a0 \u00a0 &lt;\/div&gt;\n&lt;\/div&gt;\n\u00a0 \u00a0 \n&lt;script language=\"Javascript\"&gt;\n\u00a0 \u00a0 var data = {\n\u00a0 \u00a0 \u00a0 \u00a0 labels: [\n\u00a0 \u00a0 \u00a0 \u00a0 \n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;?php\n\u00a0 \u00a0 foreach ($result as $month) {\n\u00a0 \u00a0 \u00a0 echo '\"'.$month-&gt;month.'\", '; \u00a0\n\u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ?&gt;\n\u00a0 \u00a0 \u00a0 \u00a0 ],\n\u00a0 \u00a0 \u00a0 \u00a0 datasets: [\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 label: \"Number of Posts\",\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 fillColor: \"rgba(200,200,250,0.7)\",\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 strokeColor: \"rgba(150,150,220,1)\",\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 pointColor: \"rgba(220,220,220,1)\",\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 pointStrokeColor: \"#fff\",\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 pointHighlightFill: \"#fff\",\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 pointHighlightStroke: \"rgba(220,220,220,1)\",\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 data: [\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;?php\n\u00a0 \u00a0 foreach ($result as $month) {\n\u00a0 \u00a0 \u00a0 echo '\"'.$month-&gt;cnt.'\", '; \u00a0\n\u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ?&gt;\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ]\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\n\u00a0 \u00a0 \u00a0 \u00a0 ]\n\u00a0 \u00a0 };\n\u00a0\n\u00a0 \u00a0 var ctx = document.getElementById(\"myChartMonthly\").getContext(\"2d\");\n\u00a0 \u00a0 var myNewChart = new Chart(ctx).Line(data, {\n\u00a0 \u00a0 \u00a0 \u00a0 bezierCurve: true\n\u00a0 \u00a0 });\n&lt;\/script&gt;\n&lt;?php\n\u00a0 }<\/code><\/pre>\n<p>Enregistrez le fichier mod\u00e8le et videz le cache, le trac\u00e9 sera alors rendu vivant.<\/p>\n<p>TODO\u00a0: (1) param\u00e8tre d\u00e9fini sur 12 mois par d\u00e9faut, modifiez-le en cons\u00e9quence dans l&rsquo; instruction <a href=\"https:\/\/helloacm.com\/sql-coding-exercise-customers-who-never-order\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">SQL<\/a> (2) la fonction array reverse dans php inverse les donn\u00e9es de sortie afin que l&rsquo;axe correspondant au temps (de gauche \u00e0 droite). (3) modifiez le nom de la table <a href=\"https:\/\/wordpress.mediadoma.com\/fr\/comment-activer-amp-avec-wordpress-techniques-doptimisation-amp-avec-wordpress\/\" title=\"WordPress\">WordPress<\/a> s&rsquo;il ne commence pas par le pr\u00e9fixe wp.<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">Source d&rsquo;enregistrement:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Comment afficher les statistiques du graphique du nombre mensuel de messages dans WordPress ?<\/p>\n","protected":false},"author":1,"featured_media":223872,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[893,717,832,728,841,862],"tags":[1167],"class_list":["post-232830","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code-2","category-developpeur","category-guide-pour-les-debutants","category-javascript-3","category-tutoriels","category-wordpress-3","tag-affiai-fr"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/posts\/232830","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/comments?post=232830"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/posts\/232830\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/media\/223872"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/media?parent=232830"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/categories?post=232830"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fr\/wp-json\/wp\/v2\/tags?post=232830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}