add folder EN

This commit is contained in:
argoexpert press
2024-05-24 21:37:57 +03:00
parent 4fa7a19433
commit 009f8e40c2
22 changed files with 732 additions and 80 deletions

View File

@@ -1,6 +1,10 @@
<?php
setlocale(LC_TIME, 'ru_RU.UTF-8');
define('ENPART', 740);
define('EN_PARTS', '746,741,742,743,744,745');
require get_template_directory().'/dzenews.php'; //add support dzen
function theme_setup()
@@ -150,6 +154,19 @@ function format_event_date()
return $date_text . ', ' . $time;
}
function get_published_date_in_english() {
// Получение времени публикации поста
$post_time = get_the_time('H:i');
// Получение даты публикации поста на английском языке
$post_date = get_post_time('F j, Y');
// Формирование строки с датой и временем публикации
return $post_time . ', ' . $post_date;
}
/**
* Фильтр для изменения разметки хлебных крошек Yoast SEO.
*/
@@ -672,6 +689,47 @@ function last_sticky_post() {
}
function get_latest_sticky_post_by_category($category_id) {
// Получение всех закрепленных постов
$sticky_posts = get_option('sticky_posts');
if (empty($sticky_posts)) {
return null;
}
// Получение всех постов, которые включены в закрепленные посты
$args = array(
'post__in' => $sticky_posts,
'posts_per_page' => -1, // Получаем все закрепленные посты
'ignore_sticky_posts' => 1, // Игнорируем параметры отображения закрепленных постов
);
$posts = get_posts($args);
// Получаем ID всех подрубрик рубрики
$category_ids = get_term_children($category_id, 'category');
$category_ids[] = $category_id; // Включаем основную рубрику
// Фильтрация постов по категории и её подрубрикам
$filtered_posts = array_filter($posts, function($post) use ($category_ids) {
$post_categories = wp_get_post_categories($post->ID);
return array_intersect($post_categories, $category_ids);
});
if (empty($filtered_posts)) {
return null;
}
// Сортировка постов по дате в обратном порядке
usort($filtered_posts, function($a, $b) {
return strtotime($b->post_date) - strtotime($a->post_date);
});
// Возвращаем самый последний пост
return $filtered_posts[0];
}
// отправка писем через свой почтовый сервис
function agroxpert_send_smtp_email( $phpmailer ) {
@@ -778,7 +836,7 @@ add_action('wpcf7_mail_sent', 'my_custom_mail_sent' );
//все рубрики англ версии
function get_expression_en() {
function get_expression_en( $str = false ) {
#cache result
static $res = null;
@@ -834,69 +892,71 @@ function get_expression_parts() {
}
//свой шаблон для категории и подкатегории
add_filter('category_template', function (){
$category = get_queried_object();
$parent_id = $category->category_parent; // ID родителя
$template = array(); //массив для поиска шаблонов
$templates[] = "category-{$category->slug}.php";
$templates[] = "category-{$category->term_id}.php";
function get_priority_category_en($post_id = null) {
if ($parent_id > 0){
$parent = get_category($parent_id);
$templates[] = "category-{$parent->slug}.php";
$templates[] = "category-{$parent->term_id}.php";
if ($post_id === null) {
$post_id = get_the_ID();
}
// Получаем массив категорий поста
$categories = get_the_category($post_id);
if (empty($categories)) {
return null;
}
$templates[] = 'category.php';
$en_category = null;
return locate_template($templates);
// Проходим по всем категориям поста
foreach ($categories as $category) {
// Проверяем, содержит ли название категории 'en'
if (stripos($category->name, 'en') !== false) {
$en_category = $category->name;
} else {
// Если нашли категорию, не содержащую 'en', возвращаем её название
return $category->name;
}
}
});
// Если нет категорий, кроме 'en', возвращаем категорию 'en'
return $en_category;
}
// рубрики английской версии
function use_custom_template_for_en_subcategories($template) {
if (is_category()) {
$category = get_queried_object();
// Проверяем, является ли текущая категория подрубрикой "EN"
$parent_id = $category->parent;
if ($parent_id && $parent_id == get_cat_ID('EN')) {
// Устанавливаем путь к вашему новому шаблону
$new_template = locate_template('en/category-en-sub.php');
if ($new_template) {
return $new_template;
}
}
} else if (is_single()) {
$categories = get_the_category();
foreach ($categories as $category) {
// Проверяем, является ли текущая категория или ее родительская категория "EN"
if ($category->term_id == get_cat_ID('EN') || $category->parent == get_cat_ID('EN')) {
// Устанавливаем путь к вашему новому шаблону
$new_template = locate_template('single-en.php');
if ($new_template) {
return $new_template;
}
}
}
}
return $template;
}
//свой шаблон для категории и подкатегории
add_filter( 'single_template', function ( $single_template ) {
$category = (array) get_the_category();
foreach( $category as $cat ) {
if ( file_exists(TEMPLATEPATH . "/single-{$cat->term_id}.php") ){
return TEMPLATEPATH . "/single-{$cat->term_id}.php";
}
$parent_id = $cat->parent; // шаблон гл рубрики
if ($parent_id > 0){
$parent = get_category($parent_id);
if (file_exists(TEMPLATEPATH . "/single-{$parent->term_id}.php") )
return TEMPLATEPATH . "/single-{$parent->term_id}.php";
}
}
return $single_template;
}, PHP_INT_MAX, 2 );
add_filter('template_include', 'use_custom_template_for_en_subcategories');