79 lines
2.4 KiB
PHP
79 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* БИТ.WMS Child Theme — templates/content-card.php
|
|
*
|
|
* Universal content card used in the content feed section and AJAX responses.
|
|
* Reads the current post from The Loop (global $post).
|
|
*
|
|
* @package bitwms-child
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
// Map post_type to label. For 'post' also check for "news" category.
|
|
$type_labels = array(
|
|
'case' => __( 'Кейс', 'bitwms-child' ),
|
|
'webinar' => __( 'Вебинар', 'bitwms-child' ),
|
|
'course' => __( 'Курс', 'bitwms-child' ),
|
|
'event' => __( 'Мероприятие', 'bitwms-child' ),
|
|
'material' => __( 'Материал', 'bitwms-child' ),
|
|
);
|
|
|
|
$post_type = get_post_type();
|
|
$badge_text = '';
|
|
|
|
if ( 'post' === $post_type ) {
|
|
if ( has_category( 'news' ) ) {
|
|
$badge_text = __( 'Новость', 'bitwms-child' );
|
|
} else {
|
|
$badge_text = __( 'Статья', 'bitwms-child' );
|
|
}
|
|
} elseif ( isset( $type_labels[ $post_type ] ) ) {
|
|
$badge_text = $type_labels[ $post_type ];
|
|
}
|
|
|
|
// Trim excerpt to 15 words.
|
|
$excerpt = get_the_excerpt();
|
|
if ( $excerpt ) {
|
|
$words = explode( ' ', $excerpt );
|
|
$excerpt = implode( ' ', array_slice( $words, 0, 15 ) );
|
|
if ( count( $words ) > 15 ) {
|
|
$excerpt .= '…';
|
|
}
|
|
}
|
|
?>
|
|
|
|
<article class="content-card" data-post-type="<?php echo esc_attr( $post_type ); ?>">
|
|
<a href="<?php the_permalink(); ?>" class="content-card__link">
|
|
|
|
<div class="content-card__image">
|
|
<?php if ( has_post_thumbnail() ) : ?>
|
|
<?php the_post_thumbnail( 'medium_large', array( 'alt' => esc_attr( get_the_title() ) ) ); ?>
|
|
<?php else : ?>
|
|
<div class="content-card__placeholder" aria-hidden="true"></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="content-card__body">
|
|
<?php if ( $badge_text ) : ?>
|
|
<span class="badge"><?php echo esc_html( $badge_text ); ?></span>
|
|
<?php endif; ?>
|
|
|
|
<h3 class="content-card__title"><?php the_title(); ?></h3>
|
|
|
|
<?php if ( $excerpt ) : ?>
|
|
<p class="content-card__excerpt"><?php echo esc_html( $excerpt ); ?></p>
|
|
<?php endif; ?>
|
|
|
|
<div class="content-card__meta">
|
|
<time datetime="<?php echo esc_attr( get_the_date( 'Y-m-d' ) ); ?>">
|
|
<?php echo esc_html( get_the_date( 'd.m.Y' ) ); ?>
|
|
</time>
|
|
</div>
|
|
</div>
|
|
|
|
</a>
|
|
</article>
|