add readated in pages

This commit is contained in:
argoexpert press
2026-03-05 22:37:13 +03:00
parent f99899e53e
commit 6c1bf9cbf3
27 changed files with 279 additions and 113 deletions

View File

@@ -1,4 +1,5 @@
<?php
// Задаем ID нужной категории (родительской)
$parent_cat_id = 3697; // РФО
@@ -14,21 +15,51 @@ foreach ( $subcats as $cat ) {
$category_ids[] = $cat->term_id;
}
/**
// Получаем текущий день месяца
$current_day = date('j'); // день месяца без ведущего нуля
// Формируем date_query в зависимости от дня месяца
if ($current_day <= 5) {
// Первые 5 дней месяца - показываем посты за последние 30 дней
$date_query = array(
array(
'after' => ' month ago',
'inclusive' => true,
),
);
} else {
// После 5 числа - показываем посты за текущий календарный месяц
$current_month = date('n');
$current_year = date('Y');
$date_query = array(
array(
'year' => $current_year,
'month' => $current_month,
),
);
}
*/
$date_query = array(
array(
'after' => '30 days ago',
'inclusive' => true,
),
);
// Получаем 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,
),
),
'date_query' => $date_query,
);
$random_posts = get_posts( $params );
// Если нашли посты
@@ -38,8 +69,8 @@ if ( $random_posts ) {
setup_postdata( $post );
?>
<div class="agro-widget<?if ($args['subclass'] !== '') echo ' '.$args['subclass'];?>">
<div class="agro-widget-maintitle"><a href="/rfo">Фумигация и защита растений</a></div>
<div class="agro-widget<?php if ($args['subclass'] !== '') echo ' '.$args['subclass'];?>">
<div class="agro-widget-maintitle"><a href="/rfo">СПЕЦПРОЕКТ<br>Фумигация и защита растений</a></div>
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() ) : ?>
<div>
@@ -52,7 +83,4 @@ if ( $random_posts ) {
<?php
wp_reset_postdata();
}
?>
}