Files
sportpressa_backend/template-parts/content-card.php
2026-01-08 20:53:00 +03:00

60 lines
2.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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>