File: /home/ayxmplky/public_html/wp-content/themes/tactic/template-parts/home/product-line.php
<?php
/**
* Template Part: Product Line
*
* @package tactic
*/
$products = get_posts( tactic_apply_product_lang_to_query_args( [
'post_type' => 'tactic_product',
'posts_per_page' => 12,
'post_status' => 'publish',
'orderby' => [
'menu_order' => 'ASC',
'date' => 'DESC',
],
] ) );
$lang = tactic_current_lang();
?>
<section class="section section--product-line" id="product-line">
<div class="container">
<h2 class="product-line__title"><?php echo esc_html( tactic_s( 'product_line_title' ) ); ?></h2>
<div class="product-line__viewport" data-product-line>
<div class="product-line__track" data-product-line-track role="list">
<?php if ( $products ) : ?>
<?php foreach ( $products as $p ) : ?>
<?php
$title_meta = (string) get_post_meta( $p->ID, '_tactic_product_title', true );
$title_default = $title_meta !== '' ? $title_meta : get_the_title( $p->ID );
$title_en = (string) get_post_meta( $p->ID, '_tactic_product_title_en', true );
$desc_default = (string) get_post_meta( $p->ID, '_tactic_product_desc', true );
$desc_en = (string) get_post_meta( $p->ID, '_tactic_product_desc_en', true );
$image_id = (int) get_post_meta( $p->ID, '_tactic_product_image_id', true );
if ( $desc_default === '' ) {
$excerpt = trim( (string) $p->post_excerpt );
if ( $excerpt !== '' ) {
$desc_default = $excerpt;
} else {
$content = wp_strip_all_tags( (string) $p->post_content );
$desc_default = wp_trim_words( $content, 20, '…' );
}
}
$title = ( $lang === 'en' && $title_en !== '' ) ? $title_en : $title_default;
$desc = ( $lang === 'en' && $desc_en !== '' ) ? $desc_en : $desc_default;
?>
<article class="product-card" role="listitem">
<div class="product-card__media" aria-hidden="true">
<?php if ( $image_id ) : ?>
<?php echo wp_get_attachment_image( $image_id, 'large', false, [ 'loading' => 'lazy', 'alt' => esc_attr( $title ) ] ); ?>
<?php elseif ( has_post_thumbnail( $p->ID ) ) : ?>
<?php echo get_the_post_thumbnail( $p->ID, 'large', [ 'loading' => 'lazy', 'alt' => esc_attr( $title ) ] ); ?>
<?php else : ?>
<div class="product-card__placeholder"></div>
<?php endif; ?>
</div>
<div class="product-card__text">
<h3 class="product-card__title"><?php echo esc_html( $title ); ?></h3>
<p class="product-card__desc"><?php echo esc_html( $desc ); ?></p>
</div>
</article>
<?php endforeach; ?>
<?php else : ?>
<article class="product-card" role="listitem">
<div class="product-card__media" aria-hidden="true">
<div class="product-card__placeholder"></div>
</div>
<div class="product-card__text">
<h3 class="product-card__title"><?php echo esc_html( tactic_s( 'product_empty_title' ) ); ?></h3>
<p class="product-card__desc"><?php echo esc_html( tactic_s( 'product_empty_desc' ) ); ?></p>
</div>
</article>
<?php endif; ?>
</div>
</div>
</div>
</section>