update theme
This commit is contained in:
@@ -29,6 +29,14 @@ function theme_enqueue_styles_scripts()
|
||||
|
||||
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');
|
||||
|
||||
@@ -209,66 +217,18 @@ function custom_pagination($query = null)
|
||||
echo '</div></div>';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* param string $postType - тип поста
|
||||
* param int $countPerPage - количество отображаемых постов на странице
|
||||
* param string $orderBy - относительно какого поля будем проиводить сортировку
|
||||
* param string $order - сортировка по возрастанию/убыванию (DESC,ASC)
|
||||
* param string $categorySlug - slug категории из которой выводить посты
|
||||
*
|
||||
* */
|
||||
function get_post_query(string $postType, int $countPerPage, string $order, string $orderBy = 'date', string $categorySlug = null)
|
||||
{
|
||||
$posts = new WP_Query([
|
||||
'category_name' => $categorySlug,
|
||||
'post_type' => $postType, // Указываем нужный тип поста
|
||||
'posts_per_page' => $countPerPage, // Получаем только один самый последний пост
|
||||
'orderby' => $orderBy, // Сортируем по дате публикации
|
||||
'order' => $order // В порядке убывания
|
||||
]);
|
||||
|
||||
return $posts;
|
||||
}
|
||||
|
||||
|
||||
function cyrillic_to_latin($title)
|
||||
{
|
||||
$map = array(
|
||||
'а' => 'a', 'б' => 'b', 'в' => 'v',
|
||||
'г' => 'g', 'д' => 'd', 'е' => 'e',
|
||||
'ё' => 'yo', 'ж' => 'zh', 'з' => 'z',
|
||||
'и' => 'i', 'й' => 'j', 'к' => 'k',
|
||||
'л' => 'l', 'м' => 'm', 'н' => 'n',
|
||||
'о' => 'o', 'п' => 'p', 'р' => 'r',
|
||||
'с' => 's', 'т' => 't', 'у' => 'u',
|
||||
'ф' => 'f', 'х' => 'h', 'ц' => 'c',
|
||||
'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sch',
|
||||
'ь' => '', 'ы' => 'y', 'ъ' => '',
|
||||
'э' => 'e', 'ю' => 'yu', 'я' => 'ya',
|
||||
);
|
||||
|
||||
$title = str_replace(array_keys($map), array_values($map), mb_strtolower($title));
|
||||
|
||||
// Дополнительно заменяем пробелы на дефисы и удаляем нежелательные символы
|
||||
$title = preg_replace('/[^A-Za-z0-9-]+/', '-', $title);
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/*add_filter('sanitize_title', 'cyrillic_to_latin', 9);
|
||||
add_filter('sanitize_file_name', 'cyrillic_to_latin', 9);*/
|
||||
|
||||
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((new WP_Query(array('post_type' => 'post', 'posts_per_page' => 10)))->query_vars), // Параметры запроса
|
||||
'posts' => json_encode($query->query_vars), // Параметры запроса
|
||||
'current_page' => get_query_var('paged') ? get_query_var('paged') : 1, // Текущая страница
|
||||
'max_page' => (new WP_Query(array('post_type' => 'post', 'posts_per_page' => 10)))->max_num_pages // Максимальное количество страниц
|
||||
'max_page' => $query->max_num_pages // Максимальное количество страниц
|
||||
));
|
||||
}
|
||||
add_action('wp_enqueue_scripts', 'my_theme_scripts');
|
||||
@@ -303,25 +263,15 @@ add_filter('wpcf7_form_elements', function ($content) {
|
||||
return $content;
|
||||
});
|
||||
|
||||
function show_post_image($post = null, $size = 'medium')
|
||||
function show_post_image($post = null, $size = 'large')
|
||||
{
|
||||
if (has_post_thumbnail($post)) {
|
||||
return get_the_post_thumbnail($post, $size);
|
||||
} else {
|
||||
// Вывод изображения-заглушки
|
||||
return '<img src="' . get_template_directory_uri() . '/noimage.jpg">';
|
||||
}
|
||||
}
|
||||
|
||||
function get_post_image($post = null)
|
||||
{
|
||||
if (has_post_thumbnail($post)) {
|
||||
return get_the_post_thumbnail_url($post, 'medium');
|
||||
} else {
|
||||
return get_template_directory_uri() . '/noimage.jpg';
|
||||
}
|
||||
}
|
||||
|
||||
add_action('rest_api_init', function () {
|
||||
register_rest_route('agroexpert/v1', '/posts-by-date/', array(
|
||||
'methods' => 'GET',
|
||||
@@ -534,16 +484,6 @@ function change_image_size_dimensions()
|
||||
|
||||
add_action('init', 'change_image_size_dimensions');
|
||||
|
||||
function remove_srcset_attribute($attr)
|
||||
{
|
||||
if (isset($attr['srcset'])) {
|
||||
unset($attr['srcset']); // Удаляем srcset
|
||||
}
|
||||
return $attr;
|
||||
}
|
||||
add_filter('wp_get_attachment_image_attributes', 'remove_srcset_attribute', 10, 1);
|
||||
|
||||
|
||||
add_filter('big_image_size_threshold', '__return_false');
|
||||
|
||||
function auto_add_category_by_slug_to_new_post($post_ID, $post, $update)
|
||||
@@ -566,7 +506,7 @@ function get_category_name($post = null)
|
||||
return $category->slug !== 'all-events';
|
||||
});
|
||||
$categories = array_values($categories);
|
||||
$category_name = !empty($categories) ? esc_html($categories[0]->name) : '';
|
||||
$category_name = !empty($categories) ? esc_html($categories[0]->name) : 'Все события';
|
||||
|
||||
return $category_name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user