From 655a492022d5dac10cf832c40fd2d63d3b792aed Mon Sep 17 00:00:00 2001 From: Vij Project Date: Tue, 22 Apr 2025 00:54:04 +0300 Subject: [PATCH] add widget pets --- blocks/header-pets.php | 8 ------- blocks/pets.php | 51 +++++++++++++++++++++++++++++++++++++++ footer-pets.php | 14 +++++++++++ footer.php | 4 ++-- functions.php | 54 ++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 blocks/pets.php diff --git a/blocks/header-pets.php b/blocks/header-pets.php index fe4d552..935c6b9 100644 --- a/blocks/header-pets.php +++ b/blocks/header-pets.php @@ -75,14 +75,6 @@ -
  • - - - - - -
  • -
  • diff --git a/blocks/pets.php b/blocks/pets.php new file mode 100644 index 0000000..4df1955 --- /dev/null +++ b/blocks/pets.php @@ -0,0 +1,51 @@ + $parent_cat_id, + 'hide_empty' => false, +) ); + +// Собираем все ID: родительская + подкатегории +$category_ids = array( $parent_cat_id ); +foreach ( $subcats as $cat ) { + $category_ids[] = $cat->term_id; +} + +// Получаем 3 случайных поста из этих категорий +$args = array( + 'category__in' => $category_ids, + 'posts_per_page' => 3, + 'post_status' => 'publish', + 'orderby' => 'rand' +); + +$random_posts = get_posts( $args ); + +// Если нашли посты +if ( $random_posts ) { + // Выбираем случайный один из трёх + $post = $random_posts[ array_rand( $random_posts ) ]; + setup_postdata( $post ); + ?> + + + + + + \ No newline at end of file diff --git a/footer-pets.php b/footer-pets.php index eaec674..64f92c9 100644 --- a/footer-pets.php +++ b/footer-pets.php @@ -252,6 +252,20 @@ window.yaContextCb.push(()=>{ + + + + + + + + + + + + + + diff --git a/footer.php b/footer.php index 8d606dd..0f7436b 100644 --- a/footer.php +++ b/footer.php @@ -22,8 +22,8 @@ ?> - + get_template_part( '/blocks/pets'); + //get_blocks_gen( 'citats' );?> '']);?> diff --git a/functions.php b/functions.php index 2db14fa..ce60ed1 100644 --- a/functions.php +++ b/functions.php @@ -123,7 +123,7 @@ function vij_send_smtp_email( PHPMailer $phpmailer ) { $phpmailer->SMTPSecure = 'ssl'; $phpmailer->From = 'info@vetandlife.ru'; $phpmailer->FromName = 'Ветеринария и жизнь'; -}*/ +} function vij_send_smtp_email( PHPMailer $phpmailer ) { $phpmailer->isSMTP(); @@ -138,7 +138,25 @@ function vij_send_smtp_email( PHPMailer $phpmailer ) { } -add_action( 'phpmailer_init', 'vij_send_smtp_email' ); +//add_action( 'phpmailer_init', 'vij_send_smtp_email' );*/ + + +function agroxpert_send_smtp_email( $phpmailer ) { + + $phpmailer->isSMTP(); + $phpmailer->Host = 'mail.vetandlife.ru'; + $phpmailer->SMTPAuth = true; + $phpmailer->Port = 465; + $phpmailer->Username = 'ak@mail.agroexpert.press'; + $phpmailer->Password = 'zhjk-ip-899-Jlie-Uisje3'; + $phpmailer->SMTPSecure = 'ssl'; + $phpmailer->From = 'ak@mail.agroexpert.press'; + $phpmailer->FromName = 'Андрей Кувшинов'; + +} + +add_action( 'phpmailer_init', 'agroxpert_send_smtp_email' ); + db_config(DB_NAME, 'mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASSWORD); @@ -1119,4 +1137,36 @@ function restrict_author_publish_posts( $data ) { } add_filter( 'wp_insert_post_data', 'restrict_author_publish_posts' ); +function replace_first_figure_in_content($content) { + global $post; + + if (!isset($post->ID)) { + return $content; + } + + // Ищем первое
    ...
    + if (preg_match('/.*?<\/figure>/is', $content, $match)) { + $original_figure = $match[0]; + + // Извлекаем
    (если есть) + $caption = ''; + if (preg_match('/(.*?)<\/figcaption>/is', $original_figure, $caption_match)) { + $caption = $caption_match[1]; // только содержимое + } + + // Генерируем HTML изображения + $replacement = render_webp_picture_by_post($post->ID); + + // Добавляем подпись, если есть + if (!empty($caption)) { + $replacement .= '
    ' . esc_html($caption) . '
    '; + } + + // Заменяем первое вхождение
    ...
    на $replacement + $content = preg_replace('/.*?<\/figure>/is', $replacement, $content, 1); + } + + return $content; +} +