Files
agroexpert/category-rfo.php

54 lines
1.9 KiB
PHP
Raw Normal View History

2025-06-16 00:24:13 +03:00
<?php get_header( 'rfo' ); ?>
2025-06-18 13:44:08 +03:00
<div class="content-rfo">
<? $current_category = get_queried_object();
if ($current_category->name !== 'РФО') {
get_template_part( 'rfo/breadcrumbs-rfo' );
}
?>
<div class="rfo__rubric"><?=$current_category->name; ?></div>
<div class="articles-columns-rfo">
2025-06-16 00:24:13 +03:00
<?php
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
2025-06-18 13:44:08 +03:00
// Проверяем, есть ли у текущей рубрики родительская рубрика
if ($current_category->parent == 0) {
// Это родительская рубрика - получаем все её подрубрики
$child_categories = get_categories(array(
'child_of' => $current_category->term_id,
'hide_empty' => false
));
// Собираем ID всех подрубрик + ID текущей родительской
$category_ids = array($current_category->term_id);
foreach ($child_categories as $child) {
$category_ids[] = $child->term_id;
}
$args = array(
'post_type' => 'post',
'posts_per_page' => 14,
'paged' => $paged,
'category__in' => $category_ids
);
} else {
// Это подрубрика - выводим только её посты
$args = array(
'post_type' => 'post',
'posts_per_page' => 14,
'paged' => $paged,
'category__in' => array($current_category->term_id)
);
}
2025-06-16 00:24:13 +03:00
$query = new WP_Query($args);
?>
2025-06-18 13:44:08 +03:00
<?php get_template_part('rfo/post-list', null, ['query' => $query]); ?>
2025-06-16 00:24:13 +03:00
</div>
<?php custom_pagination(); ?>
</div>
<?php get_footer( 'rfo' ); ?>