add files

This commit is contained in:
2026-01-08 20:53:00 +03:00
commit a1393e8b13
19 changed files with 970 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
<?php
// template-parts/content-card.php
$post_id = get_the_ID();
?>
<div class="news-item">
<?php if (has_post_thumbnail()) : ?>
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('medium-thumbnail'); ?>
</a>
</div>
<?php endif; ?>
<h2 class="news-item-title">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h2>
<?php
// Проверяем, является ли это страницей тега
if (is_tag()) {
// Получаем все категории поста
$categories = get_the_category();
if (!empty($categories)) {
// Находим самую первую родительскую категорию
$top_parent = $categories[0];
// Если у категории есть родитель, поднимаемся вверх по иерархии
while ($top_parent->parent != 0) {
$top_parent = get_category($top_parent->parent);
}
// Выводим родительскую категорию
echo '<div class="news-item-info">';
echo '<span class="news-item-info-part">';
echo '<a href="' . esc_url(get_category_link($top_parent->term_id)) . '">';
echo esc_html($top_parent->name);
echo '</a>';
echo '</span>';
echo '</div>';
}
} else {
// Если это не страница тега, используем существующую логику
$subcategory = get_first_subcategory($post_id);
if ($subcategory) :
?>
<div class="news-item-info">
<span class="news-item-info-part">
<a href="<?php echo esc_url($subcategory['url']); ?>">
<?php echo esc_html($subcategory['name']); ?>
</a>
</span>
</div>
<?php
endif;
}
?>
</div>