add widget pets
This commit is contained in:
@@ -75,14 +75,6 @@
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="https://ok.ru/pitomcy.vetandlife" title="Одноклассники" target="_blank">
|
||||
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="20" cy="20" r="19.5" stroke="#7A7A7A"/>
|
||||
<path fill="#7A7A7A" d="M20.2,11c-2.6,0-4.7,2.1-4.7,4.7s2.1,4.7,4.7,4.7s4.7-2.1,4.7-4.7l0,0C24.8,13.1,22.8,11,20.2,11z M20.2,17.6 c-1.1,0-1.9-0.9-1.9-1.9c0-1.1,0.9-1.9,1.9-1.9s1.9,0.9,1.9,1.9l0,0C22.1,16.7,21.3,17.6,20.2,17.6L20.2,17.6z M21.8,24 c1.1-0.2,2.1-0.7,3-1.3c0.6-0.4,0.6-1.2,0.2-1.8s-1.2-0.6-1.8-0.2l0,0c-0.9,0.6-2,0.9-3.2,0.9c-1.1,0-2.2-0.3-3.2-0.9 c-0.6-0.4-1.4-0.3-1.8,0.2c-0.4,0.6-0.3,1.4,0.2,1.8l0,0c0.9,0.7,2,1.1,3.1,1.3l-2.7,2.8c-0.5,0.5-0.5,1.3,0,1.8 c0.5,0.5,1.3,0.5,1.8,0c0,0,0,0,0-0.1l2.7-2.5l2.7,2.7c0.5,0.5,1.3,0.4,1.8-0.1s0.5-1.2,0-1.7L21.8,24z"/>
|
||||
</svg></a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="https://dzen.ru/pitomcy_vetandlife?favid=254162793" title="Дзен" target="_blank">
|
||||
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
|
||||
51
blocks/pets.php
Normal file
51
blocks/pets.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
// Задаем ID нужной категории (родительской)
|
||||
$parent_cat_id = 14; // замените на нужный ID рубрики
|
||||
|
||||
// Получим 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 случайных поста из этих категорий
|
||||
$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 );
|
||||
?>
|
||||
|
||||
<div class="pets-widget">
|
||||
<div class="pets-widget-maintitle"><a href="/pets">Питомцы</a></div>
|
||||
<a href="<?php the_permalink(); ?>">
|
||||
<?php if ( has_post_thumbnail() ) : ?>
|
||||
<div>
|
||||
<?php the_post_thumbnail('medium'); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<h3 class="pets-widget-title"><?php the_title(); ?></h3>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
wp_reset_postdata();
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user