{"id":232774,"date":"2023-01-28T14:06:00","date_gmt":"2023-01-28T11:06:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=232774"},"modified":"2023-02-02T16:24:15","modified_gmt":"2023-02-02T13:24:15","slug":"jak-pokazati-statistiku-diagrami-misjachnoi-kilkosti-dopisiv-u-wordpress","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/uk\/jak-pokazati-statistiku-diagrami-misjachnoi-kilkosti-dopisiv-u-wordpress\/","title":{"rendered":"\u042f\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0438 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0434\u0456\u0430\u0433\u0440\u0430\u043c\u0438 \u043c\u0456\u0441\u044f\u0447\u043d\u043e\u0457 \u043a\u0456\u043b\u044c\u043a\u043e\u0441\u0442\u0456 \u0434\u043e\u043f\u0438\u0441\u0456\u0432 \u0443 WordPress?"},"content":{"rendered":"\n<p>URL-\u0430\u0434\u0440\u0435\u0441\u0430: <a href=\"https:\/\/helloacm.com\/archives-of-pagesposts\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">https:\/\/helloacm.com\/archives-of-pagesposts\/<\/a> \u043f\u043e\u043a\u0430\u0437\u0443\u0454 \u0441\u043f\u0438\u0441\u043e\u043a \u0456\u0441\u0442\u043e\u0440\u0438\u0447\u043d\u0438\u0445 \u043f\u0443\u0431\u043b\u0456\u043a\u0430\u0446\u0456\u0439, \u0456 \u044f \u0434\u043e\u0434\u0430\u0432 \u043d\u0430\u0441\u0442\u0443\u043f\u043d\u0443 \u0433\u0430\u0440\u043d\u0443 \u0446\u0438\u0444\u0440\u0443, \u044f\u043a\u0430 \u0432\u0456\u0434\u043e\u0431\u0440\u0430\u0436\u0430\u0454 \u043a\u0456\u043b\u044c\u043a\u0456\u0441\u0442\u044c \u043f\u0443\u0431\u043b\u0456\u043a\u0430\u0446\u0456\u0439 \u0437\u0430 \u043a\u043e\u0436\u0435\u043d \u043c\u0456\u0441\u044f\u0446\u044c.<\/p>\n<p>chart-posts-per-months-wordpress-php-js<\/p>\n<p>\u0412\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0431\u0430\u0447\u0438\u0442\u0438 \u0433\u0440\u0443\u0431\u0443 \u0434\u0456\u044f\u043b\u044c\u043d\u0456\u0441\u0442\u044c \u043f\u0440\u043e\u0442\u044f\u0433\u043e\u043c \u043e\u0441\u0442\u0430\u043d\u043d\u0456\u0445 12 \u043c\u0456\u0441\u044f\u0446\u0456\u0432. \u0422\u0430\u043a, \u043c\u0438 \u0456\u043d\u043e\u0434\u0456 \u043b\u0456\u043d\u0443\u0454\u043c\u043e\u0441\u044f \u043f\u0440\u043e\u0442\u044f\u0433\u043e\u043c \u0440\u043e\u043a\u0443. <a href=\"https:\/\/wordpress.mediadoma.com\/uk\/jak-stvoriti-storinku-arhiviv-rezjume-dlja-vsih-publikacij-storinok-wordpress-za-dopomogoju-php\/\" title=\"\u0423 \u0446\u044c\u043e\u043c\u0443 \u0434\u043e\u043f\u0438\u0441\u0456\">\u0423 \u0446\u044c\u043e\u043c\u0443 \u0434\u043e\u043f\u0438\u0441\u0456<\/a> \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e, \u044f\u043a \u0441\u0442\u0432\u043e\u0440\u0438\u0442\u0438 \u0442\u0430\u043a\u0443 \u0441\u0442\u043e\u0440\u0456\u043d\u043a\u0443, \u0449\u043e\u0431 \u043e\u0442\u0440\u0438\u043c\u0430\u0442\u0438 \u0434\u043e\u043f\u0438\u0441\u0438, \u0456 \u043d\u0430\u0441\u0442\u0443\u043f\u043d\u0438\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u0430 \u0434\u043e\u0434\u0430\u0442\u0438 \u043d\u0430 \u0442\u0443 \u0436 \u0441\u0442\u043e\u0440\u0456\u043d\u043a\u0443, \u0449\u043e\u0431 \u043f\u043e\u0431\u0443\u0434\u0443\u0432\u0430\u0442\u0438 \u0433\u0440\u0430\u0444\u0456\u043a.<\/p>\n<p>\u041d\u0430\u043c \u043f\u043e\u0442\u0440\u0456\u0431\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u044e \u0431\u0456\u0431\u043b\u0456\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/helloacm.com\/how-to-invoke-apis-the-javascriptajax-example\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">JavaScript<\/a> Chart, \u044f\u043a\u0443 \u043c\u043e\u0436\u043d\u0430 \u0437\u043d\u0430\u0439\u0442\u0438 \u0437\u0430 \u0430\u0434\u0440\u0435\u0441\u043e\u044e: <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>\u0417\u0431\u0435\u0440\u0435\u0436\u0456\u0442\u044c \u0444\u0430\u0439\u043b \u0448\u0430\u0431\u043b\u043e\u043d\u0443 \u0442\u0430 \u043e\u0447\u0438\u0441\u0442\u0456\u0442\u044c \u043a\u0435\u0448, \u0442\u043e\u0434\u0456 \u0441\u044e\u0436\u0435\u0442 \u043e\u0436\u0438\u0432\u0435.<\/p>\n<p>TODO: (1) \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u043d\u0430 12 \u043c\u0456\u0441\u044f\u0446\u0456\u0432 \u0437\u0430 \u0437\u0430\u043c\u043e\u0432\u0447\u0443\u0432\u0430\u043d\u043d\u044f\u043c, \u0432\u0456\u0434\u043f\u043e\u0432\u0456\u0434\u043d\u043e \u0437\u043c\u0456\u043d\u0456\u0442\u044c \u0446\u0435 \u0432 \u0456\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0456\u0457 <a href=\"https:\/\/helloacm.com\/sql-coding-exercise-customers-who-never-order\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">SQL (2)<\/a> \u0444\u0443\u043d\u043a\u0446\u0456\u044f \u0440\u0435\u0432\u0435\u0440\u0441\u0443<a href=\"https:\/\/helloacm.com\/how-to-enable-amp-with-wordpress-amp-optimisation-techniques-with-wordpress\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external\"><\/a> \u043c\u0430\u0441\u0438\u0432\u0443 \u0432 php \u043f\u043e\u0432\u0435\u0440\u0442\u0430\u0454 \u0432\u0438\u0445\u0456\u0434\u043d\u0456 \u0434\u0430\u043d\u0456 \u0442\u0430\u043a\u0438\u043c \u0447\u0438\u043d\u043e\u043c, \u0449\u043e\u0431 \u0432\u0456\u0441\u044c \u0432\u0456\u0434\u043f\u043e\u0432\u0456\u0434\u0430\u043b\u0430 \u0447\u0430\u0441\u0443 (\u0437\u043b\u0456\u0432\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043e). (3) \u0437\u043c\u0456\u043d\u0438\u0442\u0438 \u043d\u0430\u0437\u0432\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0456 <a href=\"https:\/\/wordpress.mediadoma.com\/uk\/jak-uvimknuti-amp-u-wordpress-metodi-optimizacii-amp-za-dopomogoju-wordpress\/\" title=\"WordPress\">WordPress<\/a>, \u044f\u043a\u0449\u043e \u0432\u043e\u043d\u0430 \u043d\u0435 \u043f\u043e\u0447\u0438\u043d\u0430\u0454\u0442\u044c\u0441\u044f \u0437 \u043f\u0440\u0435\u0444\u0456\u043a\u0441\u0430 wp.<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">\u0414\u0436\u0435\u0440\u0435\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0443:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u042f\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0438 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043c\u0456\u0441\u044f\u0447\u043d\u043e\u0457 \u043a\u0456\u043b\u044c\u043a\u043e\u0441\u0442\u0456 \u0434\u043e\u043f\u0438\u0441\u0456\u0432 \u0443 \u0434\u0456\u0430\u0433\u0440\u0430\u043c\u0456 \u0432 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":[735,869,839,902,849,725],"tags":[1174],"class_list":["post-232774","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript-10","category-wordpress-10","category-kerivnytstvo-dlia-pochatkivtsiv","category-kod-3","category-pidruchnyky","category-rozrobnyk","tag-affiai-uk"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts\/232774","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/comments?post=232774"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts\/232774\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/media\/223872"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/media?parent=232774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/categories?post=232774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/tags?post=232774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}