add update rubrics
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
$args = array(
|
||||
'post_type' => 'post', // Или ваш пользовательский тип постов, если необходимо
|
||||
'post__not_in' => [ $mainpost_id ],
|
||||
'posts_per_page' => 10, // Количество постов на странице
|
||||
'posts_per_page' => 20, // Количество постов на странице
|
||||
'orderby' => 'date', // сортировка по дате
|
||||
'order' => 'DESC', // по убыванию (сначала новые)
|
||||
'ignore_sticky_posts' => 1,
|
||||
@@ -18,7 +18,7 @@
|
||||
?>
|
||||
<?php get_template_part('en/post-list-en', null, ['large_first_image' => false, 'query' => $query]); ?>
|
||||
</div>
|
||||
<button class="articles-preview__show-next">More Read</button>
|
||||
<!--<button class="articles-preview__show-next">More Read</button>-->
|
||||
</div>
|
||||
|
||||
<?php get_footer( 'en' ); ?>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
|
||||
$args = array(
|
||||
'post_type' => 'post',
|
||||
'posts_per_page' => 5,
|
||||
'posts_per_page' => 9,
|
||||
'paged' => $paged,
|
||||
'category__in' => get_queried_object_id()
|
||||
);
|
||||
|
||||
10
en/menu-primary-en.php
Normal file
10
en/menu-primary-en.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$menu_id = 761;
|
||||
$menu_items = wp_get_nav_menu_items($menu_id);
|
||||
?>
|
||||
<?php foreach ($menu_items ?: [] as $menu_item):?>
|
||||
<li class="menu-item">
|
||||
<a href="<?=esc_url($menu_item->url);?>"><?=$menu_item->title?></a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
@@ -960,3 +960,99 @@ function use_custom_template_for_en_subcategories($template) {
|
||||
|
||||
add_filter('template_include', 'use_custom_template_for_en_subcategories');
|
||||
|
||||
|
||||
/**
|
||||
* update rubrics
|
||||
*/
|
||||
|
||||
function add_posts_to_category_744() {
|
||||
// Получаем ID рубрики 740 и всех ее подрубрик
|
||||
$parent_category_id = 740;
|
||||
$subcategories = get_categories(array(
|
||||
'child_of' => $parent_category_id,
|
||||
'hide_empty' => false
|
||||
));
|
||||
|
||||
// Массив ID всех подрубрик 740
|
||||
$subcategory_ids = wp_list_pluck($subcategories, 'term_id');
|
||||
$all_category_ids = array_merge(array($parent_category_id), $subcategory_ids);
|
||||
|
||||
// Запрос для получения постов, которые имеют рубрику 740 или любую из ее подрубрик
|
||||
$args = array(
|
||||
'post_type' => 'post',
|
||||
'posts_per_page' => -1,
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'category',
|
||||
'field' => 'term_id',
|
||||
'terms' => $all_category_ids,
|
||||
'operator' => 'IN'
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Получаем все посты с указанной рубрикой или ее подрубриками
|
||||
$query = new WP_Query($args);
|
||||
|
||||
if ($query->have_posts()) {
|
||||
while ($query->have_posts()) {
|
||||
$query->the_post();
|
||||
|
||||
// Получаем ID текущего поста
|
||||
$post_id = get_the_ID();
|
||||
|
||||
// Получаем все рубрики текущего поста
|
||||
$post_categories = wp_get_post_categories($post_id);
|
||||
|
||||
// Проверяем, есть ли у поста только рубрика 740
|
||||
if (count($post_categories) == 1 && in_array($parent_category_id, $post_categories)) {
|
||||
// Добавляем пост в рубрику с ID 744
|
||||
wp_set_post_categories($post_id, array_merge($post_categories, array(744)));
|
||||
} else {
|
||||
// Проверяем, если у поста есть подрубрика 740, но нет основной рубрики 740
|
||||
$has_subcategory = array_intersect($post_categories, $subcategory_ids);
|
||||
if ($has_subcategory && !in_array($parent_category_id, $post_categories)) {
|
||||
// Добавляем основную рубрику 740
|
||||
wp_set_post_categories($post_id, array_merge($post_categories, array($parent_category_id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Сбрасываем пост данные
|
||||
wp_reset_postdata();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function add_custom_admin_menu() {
|
||||
add_menu_page(
|
||||
'Update Posts Categories', // Заголовок страницы
|
||||
'Update Categories EN', // Текст меню
|
||||
'manage_options', // Возможность доступа (только администраторы)
|
||||
'update-categories', // Уникальный идентификатор страницы
|
||||
'update_categories_callback' // Функция для отображения контента страницы
|
||||
);
|
||||
}
|
||||
|
||||
add_action('admin_menu', 'add_custom_admin_menu');
|
||||
|
||||
|
||||
function update_categories_callback() {
|
||||
if (isset($_POST['update_categories'])) {
|
||||
add_posts_to_category_744();
|
||||
echo '<div class="updated"><p>Posts have been updated successfully.</p></div>';
|
||||
}
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1>Update Posts Categories</h1>
|
||||
<form method="post">
|
||||
<input type="hidden" name="update_categories" value="1">
|
||||
<p>
|
||||
<input type="submit" class="button-primary" value="Update Categories">
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
||||
<nav class="nav header__nav">
|
||||
<?php get_template_part('en/mainmenu-en'); ?>
|
||||
</nav>
|
||||
<div class="lang-switch"><a href="<?php echo home_url(); ?>">RU</a></div>
|
||||
<div class="header__right">
|
||||
<div class="header__actions">
|
||||
<a href="/search/">
|
||||
@@ -102,7 +103,7 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
||||
</div>
|
||||
<div class="header-mobile">
|
||||
<nav class="nav header-mobile__nav">
|
||||
<?php get_template_part('partials/menu-primary'); ?>
|
||||
<?php get_template_part('en/menu-primary-en'); ?>
|
||||
</nav>
|
||||
<div class="socials header-mobile__socials">
|
||||
<?php get_template_part('partials/menu-socials'); ?>
|
||||
|
||||
@@ -70,8 +70,9 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
||||
<img src="<?php echo esc_url($site_logo); ?>" alt="" />
|
||||
</a>
|
||||
<nav class="nav header__nav">
|
||||
<?php get_template_part('partials/menu-primary'); ?>
|
||||
<?php get_template_part('partials/menu-primary'); ?>
|
||||
</nav>
|
||||
|
||||
<div class="header__right">
|
||||
<div class="header__actions">
|
||||
<a href="/search/">
|
||||
|
||||
Reference in New Issue
Block a user