add rfo informers

This commit is contained in:
argoexpert press
2025-07-13 20:53:44 +03:00
parent c6cf38dc1c
commit 30d9b0bdcc
2 changed files with 68 additions and 4 deletions

58
rfo/rfo-informer.php Normal file
View File

@@ -0,0 +1,58 @@
<?php
// Задаем ID нужной категории (родительской)
$parent_cat_id = 3697; // РФО
// Получим ID подкатегорий
$subcats = get_categories( array(
'child_of' => $parent_cat_id,
'hide_empty' => false,
) );
// Собираем все ID: родительская + подкатегории
$category_ids = array( $parent_cat_id );
foreach ( $subcats as $cat ) {
$category_ids[] = $cat->term_id;
}
// Получаем 3 случайных поста из этих категорий
$params = array(
'category__in' => $category_ids,
'posts_per_page' => 3,
'post_status' => 'publish',
'orderby' => 'rand',
'date_query' => array(
array(
'after' => '1 month ago',
'inclusive' => true,
),
),
);
$random_posts = get_posts( $params );
// Если нашли посты
if ( $random_posts ) {
// Выбираем случайный один из трёх
$post = $random_posts[ array_rand( $random_posts ) ];
setup_postdata( $post );
?>
<div class="agro-widget<?if ($args['subclass'] !== '') echo ' '.$args['subclass'];?>">
<div class="agro-widget-maintitle"><a href="/forest">Фумигация и защита растений</a></div>
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() ) : ?>
<div>
<?php the_post_thumbnail('full'); ?>
</div>
<?php endif; ?>
<h3 class="agro-widget-title"><?php the_title(); ?></h3>
</a>
</div>
<?php
wp_reset_postdata();
}
?>

View File

@@ -38,8 +38,14 @@ if ( in_category('interviews') ) {
<div class="banner-left desktop"> <div class="banner-left desktop">
<?=krutilka_placement( 'left-desktop-1' );?> <?=krutilka_placement( 'left-desktop-1' );?>
</div> </div>
<?endif?>
<?php get_template_part('partials/forest-informer');?>
<?php get_template_part('partials/forest-informer');?>
<?php // get_template_part('rfo/rfo-informer');?>
<?if (function_exists('krutilka_placement')):?>
<div class="banner-left desktop"> <div class="banner-left desktop">
<?=krutilka_placement( 'left-desktop-2' );?> <?=krutilka_placement( 'left-desktop-2' );?>