__('Основное меню', 'your-theme-domain'), 'socials' => __('Соцсети', 'your-theme-domain'), 'footer-bottom' => __('Нижнее меню в подвале', 'your-theme-domain'), )); add_theme_support('custom-logo', array( 'height' => 100, 'width' => 400, 'flex-height' => true, 'flex-width' => true, )); add_theme_support('post-thumbnails'); } add_action('after_setup_theme', 'theme_setup'); function theme_enqueue_styles_scripts() { $style_ver = filemtime(get_template_directory() . '/frontend/dist/assets/main.css'); $script_ver = filemtime(get_template_directory() . '/frontend/dist/assets/main2.js'); wp_enqueue_style('main-style', get_template_directory_uri() . '/frontend/dist/assets/main.css', array(), $style_ver); wp_enqueue_script('main-script2', get_template_directory_uri() . '/frontend/dist/assets/main2.js', array(), $script_ver, true); // Preconnect for Google Fonts //wp_enqueue_style('google-fonts-preconnect', 'https://fonts.gstatic.com', [], null, 'all'); //wp_resource_hints(['https://fonts.googleapis.com', 'https://fonts.gstatic.com'], 'preconnect'); // Enqueue Google Fonts wp_enqueue_style('google-fonts-raleway', 'https://fonts.googleapis.com/css2?family=Raleway:wght@400;500;600&display=swap', false); wp_enqueue_style('google-fonts-roboto', 'https://fonts.googleapis.com/css2?family=Roboto:wght@400&display=swap', false); } add_action('wp_enqueue_scripts', 'theme_enqueue_styles_scripts'); add_filter('nav_menu_css_class', 'change_menu_item_css_class', 10, 4); function change_menu_item_css_class($classes, $item, $args, $depth) { // Удаляем нежелательные классы $classes = array_diff($classes, array('page_item', 'page-item-' . $item->ID)); $classes = array_diff($classes, array('page_item', 'page-item-' . $item->ID)); // Добавляем класс 'menu-item' $classes[] = 'menu-item'; return $classes; } function get_asset(string $path) { return get_template_directory_uri() . '/frontend/dist/' . $path; } function mytheme_widget_areas() { // Регистрация левого сайдбара register_sidebar(array( 'name' => 'Левый сайдбар', 'id' => 'left-sidebar', 'description' => 'Виджеты в этой области будут показаны в левой части сайта.', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', )); // Регистрация правого сайдбара register_sidebar(array( 'name' => 'Правый сайдбар', 'id' => 'right-sidebar', 'description' => 'Виджеты в этой области будут показаны в правой части сайта.', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', )); } add_action('widgets_init', 'mytheme_widget_areas'); class Upcoming_Events_Widget extends WP_Widget { function __construct() { parent::__construct( 'upcoming_events_widget', // ID виджета 'Upcoming Events', // Название виджета array('description' => 'Displays upcoming events') // Описание ); } public function widget($args, $instance) { include get_template_directory() . '/widgets/upcoming-events-widget-template.php'; } // Форма в админ-панели для настройки виджета public function form($instance) { $title = !empty($instance['title']) ? $instance['title'] : 'Новое название'; ?>

', '', $output); $output = str_replace('', '', $output); // Заменяем разделитель на нужный нам класс. $output = str_replace('»', '', $output); // Заменяем теги ссылок. $output = str_replace(']*>/', '', $output); return $output; } function custom_pagination($query = null) { global $wp_query; $query = $query ?: $wp_query; $current_page = max(1, get_query_var('paged')); $total_pages = $query->max_num_pages; $show_items = 3; // Количество страниц для вывода в начале и в конце $range = 1; // Диапазон страниц вокруг текущей страницы if (1 == $total_pages) { return; // Если страница всего одна, пагинация не нужна } echo ''; } function my_theme_scripts() { wp_enqueue_script('my-load-more', get_template_directory_uri() . '/js/load-more.js', array('jquery'), null, true); $query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 10)); // Передаем переменные в скрипт wp_localize_script('my-load-more', 'my_load_more_params', array( 'ajaxurl' => admin_url('admin-ajax.php'), // URL для AJAX-запроса 'posts' => json_encode($query->query_vars), // Параметры запроса 'current_page' => get_query_var('paged') ? get_query_var('paged') : 1, // Текущая страница 'max_page' => $query->max_num_pages // Максимальное количество страниц )); } add_action('wp_enqueue_scripts', 'my_theme_scripts'); function loadmore_ajax_handler() { $args = json_decode(stripslashes($_POST['query']), true); $args['paged'] = $_POST['page'] + 1; // следующая страница $args['post_status'] = 'publish'; $args['cat'] = [-17, -20, -21]; query_posts($args); if (have_posts()) : while (have_posts()) : the_post(); get_template_part('content', 'post'); endwhile; endif; die; } add_action('wp_ajax_loadmore', 'loadmore_ajax_handler'); // для авторизованных пользователей add_action('wp_ajax_nopriv_loadmore', 'loadmore_ajax_handler'); // для неавторизованных пользователей /* * Фильтр добавлен для модификации стандартной формы плагина Contact Form ( Срезаем span элементы, в которые оборачивается input ). * Работает в связке с отключенными требованиями плагина - define( 'WPCF7_AUTOP', false ); * В файле wp-config.php * */ add_filter('wpcf7_form_elements', function ($content) { $content = preg_replace('/<(span).*?class="\s*(?:.*\s)?wpcf7-form-control-wrap(?:\s[^"]+)?\s*"[^\>]*>(.*)<\/\1>/i', '\2', $content); return $content; }); function show_post_image($post = null, $size = 'large') { if (has_post_thumbnail($post)) { return get_the_post_thumbnail($post, $size); } else { return ''; } } add_action('rest_api_init', function () { register_rest_route('agroexpert/v1', '/posts-by-date/', array( 'methods' => 'GET', 'callback' => 'get_posts_by_date', 'permission_callback' => '__return_true', // Доступно для чтения всеми )); }); function get_posts_by_date($request) { global $wpdb; // Глобальный объект базы данных WordPress // SQL-запрос для получения уникальных дат публикации постов $query = " SELECT DISTINCT DATE(post_date) as date FROM {$wpdb->posts} WHERE post_status IN ('publish', 'future') AND post_type = 'post' ORDER BY date DESC "; // Выполнение запроса $result = $wpdb->get_results($query); // Преобразование результатов в массив дат $dates = array_map(function ($item) { return $item->date; }, $result); return new WP_REST_Response($dates, 200); } function setup_future_hook() { // Replace native future_post function with replacement remove_action('future_event', '_future_post_hook'); add_action('future_event', 'publish_future_post_now'); } function publish_future_post_now($id) { // Set new post's post_status to "publish" rather than "future." wp_publish_post($id); } add_action('init', 'setup_future_hook'); add_action('restrict_manage_posts', 'add_author_filter_to_posts_admin'); function add_author_filter_to_posts_admin() { global $post_type; // Убедитесь, что этот фильтр применяется только к типу поста 'post' if ('post' !== $post_type) { return; } // Получаем пользователей с ролью 'author' $authors = get_users(array('role' => '', 'orderby' => 'display_name', 'order' => 'ASC')); // Проверяем, установлен ли фильтр $selected = isset($_GET['custom_author']) ? $_GET['custom_author'] : ''; // Начинаем выводить HTML выпадающего списка echo ''; } add_action('pre_get_posts', 'filter_posts_by_custom_author'); function filter_posts_by_custom_author($query) { global $pagenow; // Применяем фильтр только в админ-панели и только для основного запроса на странице списка постов if (is_admin() && 'edit.php' === $pagenow && $query->is_main_query()) { // Проверяем, установлен ли наш фильтр if (!empty($_GET['custom_author'])) { $custom_author_id = $_GET['custom_author']; // Фильтруем посты по автору $query->set('author', $custom_author_id); } } } function custom_search_rewrite_rule() { add_rewrite_rule( '^search/$', 'index.php?s=' . get_query_var('s'), 'top' ); add_rewrite_rule('^search/?$', 'index.php?s=', 'top'); add_rewrite_rule('^search/page/([0-9]+)/?$', 'index.php?s=&paged=$matches[1]', 'top'); } add_action('init', 'custom_search_rewrite_rule'); add_filter('relevanssi_hits_filter', 'rlv_gather_categories', 99); function rlv_gather_categories($hits) { global $rlv_categories_present; $rlv_categories_present = array(); foreach ($hits[0] as $hit) { $terms = get_the_terms($hit->ID, 'category'); if (is_array($terms)) { foreach ($terms as $term) { $rlv_categories_present[$term->term_id] = $term->name; } } } asort($rlv_categories_present); return $hits; } function plural_form_extended($number, $forms, $additionalWord = '') { $cases = array(2, 0, 1, 1, 1, 2); $index = ($number % 100 > 4 && $number % 100 < 20) ? 2 : $cases[min($number % 10, 5)]; // Склонение дополнительного слова, если оно передано $additionalForm = ''; if ($additionalWord) { $additionalIndex = $index > 0 ? 1 : 0; // Простая логика для "найдено" $additionalForm = $additionalWord[$additionalIndex] . ' '; } return $additionalForm . $number . ' ' . $forms[$index]; } add_filter('wpseo_breadcrumb_links', 'custom_search_breadcrumbs'); function custom_search_breadcrumbs($links) { if (is_search()) { // Получаем поисковый запрос $search_query = get_search_query(); // Перебираем все ссылки, чтобы найти и изменить нужный элемент foreach ($links as &$link) { if (strpos($link['text'], 'Результаты поиска') !== false) { if ($search_query === "") { $link['text'] = 'Поиск'; } else { $link['text'] = 'Результаты поиска для запроса "' . esc_html($search_query) . '"'; } $link['url'] = home_url('/search/') . urlencode($search_query) . '/'; break; // Прерываем цикл после изменения нужного элемента } } unset($link); } return $links; } function include_future_posts_in_date_archive($query) { // Убедимся, что мы находимся в основном запросе и на странице архива по дате if ($query->is_main_query() && $query->is_date()) { // Изменяем запрос так, чтобы он включал посты с датой публикации в будущем $query->set('post_status', array('publish', 'future')); } } add_action('pre_get_posts', 'include_future_posts_in_date_archive'); function template_500_error($template) { // Проверяем, является ли текущая страница страницей ошибки 500 if (is_500()) { return get_stylesheet_directory() . '/500.php'; // Путь к вашему собственному шаблону 500 ошибки } return $template; } add_filter('template_include', 'template_500_error'); function is_500() { // Проверяем, является ли текущий код состояния HTTP 500 return get_query_var('error', false) === 500; } function change_image_size_dimensions() { update_option('large_size_w', 1080); update_option('large_size_h', 0); update_option('medium_size_w', 400); update_option('medium_size_h', 0); } add_action('init', 'change_image_size_dimensions'); add_filter('big_image_size_threshold', '__return_false'); function auto_add_category_by_slug_to_new_post($post_ID, $post, $update) { $category_slug = 'all-events'; // Slug рубрики для добавления $category = get_term_by('slug', $category_slug, 'category'); // Если рубрика с таким slug существует if ($category && !has_category($category->term_id, $post_ID)) { wp_set_post_categories($post_ID, array($category->term_id), true); } } add_action('save_post', 'auto_add_category_by_slug_to_new_post', 10, 3); function get_category_name($post = null) { $categories = get_the_category($post); $categories = array_filter($categories, function (WP_Term $category) { return $category->slug !== 'all-events'; }); $categories = array_values($categories); $category_name = !empty($categories) ? esc_html($categories[0]->name) : 'Все события'; return $category_name; } // Добавляем функцию для формирования мета-тегов страницы function custom_meta_tags() { $meta_tags = ''; $sitename = get_bloginfo('name'); // Получаем заголовок страницы if (is_single() || is_page()) { $post = get_post(); // Получаем объект текущего поста или страницы $title = get_the_title($post).' - '.$sitename; // Получаем заголовок текущего поста или страницы $description = get_the_excerpt($post); // Получаем отрывок текущего поста или страницы $tags = get_the_tags($post); // Получаем теги текущего поста или страницы $keywords = ''; // Переменная для хранения ключевых слов if ($tags) { $keywords = implode(', ', wp_list_pluck($tags, 'name')); // Формируем строку с тегами через запятую } } elseif (is_category()) { $category = get_queried_object(); // Получаем объект текущей рубрики $title = $category->name.' - '.$sitename; // Получаем название текущей рубрики $description = $category->description; // Получаем описание текущей рубрики $keywords = $title; // Ключевые слова - название рубрики } elseif (is_home()) { $title = $sitename; // Получаем название сайта для главной страницы $description = get_bloginfo('description'); // Получаем описание сайта для главной страницы $keywords = ''; // Для главной страницы ключевые слова оставляем пустыми } // Добавляем мета-теги только в случае, если их значения не пусты if (!empty($title)) { $meta_tags .= '' . esc_html($title) . ''; } if (!empty($description)) { $meta_tags .= ''; } if (!empty($keywords)) { $meta_tags .= ''; } // Выводим мета-теги echo $meta_tags; }