add eng version

This commit is contained in:
argoexpert press
2024-05-22 21:02:50 +03:00
parent 9f8ad06536
commit 097eefe379
14 changed files with 435 additions and 20 deletions

View File

@@ -223,7 +223,7 @@ 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));
$query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 10, 'cat' => '19'));
// Передаем переменные в скрипт
wp_localize_script('my-load-more', 'my_load_more_params', array(
@@ -777,3 +777,126 @@ add_action('wpcf7_mail_sent', 'my_custom_mail_sent' );
}
//все рубрики англ версии
function get_expression_en() {
#cache result
static $res = null;
if ($res !== null) {
return $res;
}
$parent_cat_id = 740;
// Получаем все подрубрики данной рубрики
$subcategories = get_terms(array(
'taxonomy' => 'category',
'child_of' => $parent_cat_id,
'hide_empty' => false,
'fields' => 'ids'
));
// Добавляем ID родительской рубрики в начало массива подрубрик
array_unshift($subcategories, $parent_cat_id);
$res = $subcategories;
return $res;
}
// возвращаем все исключенные рубрики
function get_expression_parts() {
#cache result
static $res = null;
if ($res !== null) {
return $res;
}
$subcategories_en = get_expression_en();
$additional_excludes = [ '17', '20', '21', $parent_cat_id ];
$all_excludes = array_merge( $additional_excludes, $subcategories_en );
$res = implode(',', $all_excludes);
// Преобразуем массив ID в строку, разделенную запятыми
return $res;
}
//свой шаблон для категории и подкатегории
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";
if ($parent_id > 0){
$parent = get_category($parent_id);
$templates[] = "category-{$parent->slug}.php";
$templates[] = "category-{$parent->term_id}.php";
}
$templates[] = 'category.php';
return locate_template($templates);
});
//свой шаблон для категории и подкатегории
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 );