task 17075 | сделал подсчет просмотров в статье

This commit is contained in:
web_103.2 committed 2026-10-15 16:41:06 +03:00
1 parent 9e21c34547
commit 73a51cf6f4
2 files changed
+16 -1

No files matched your search

+8
View File
@@ -3,6 +3,14 @@
// Отключить табы в редакторе групп полей ACF
add_filter('acf/field_group/disable_field_settings_tabs', '__return_true');
// Просмотры изменяются автоматически, поле в админке доступно только для просмотра.
add_filter('acf/prepare_field/name=viewers', function ($field) {
if (is_admin()) {
$field['disabled'] = 1;
}
return $field;
});
// Страница опций ACF
if (function_exists('acf_add_options_page')) {
+8 -1
View File
@@ -5,6 +5,13 @@
<?php get_breadcrumbs(); ?>
<?php
$post_id = get_the_ID();
$views = (int) get_field('viewers', $post_id);
if (!current_user_can('manage_options')) {
$views++;
update_field('viewers', $views, $post_id);
}
$parent_id = is_singular('news') ? 82 : 42;
$terms = get_the_terms(get_the_ID(), 'article_category');
$article_content = get_field('article_content');
@@ -65,7 +72,7 @@
<path d="M2.2 12s3.7-6 9.8-6 9.8 6 9.8 6-3.7 6-9.8 6-9.8-6-9.8-6Z"></path>
<circle cx="12" cy="12" r="2.8"></circle>
</svg>
<span>Просмотры: <strong>—</strong></span>
<span>Просмотры: <strong><?php echo esc_html(number_format_i18n($views)); ?></strong></span>
</div>
</div>
</div>