/* ──────────────────────────────────────────────
FEATURED THUMBNAILS (SAFE + OPTIMIZED)
────────────────────────────────────────────── */
function render_post_thumbnail($post_id) {
$thumb_id = get_post_thumbnail_id($post_id);
if (!$thumb_id) return;
$title = get_the_title($post_id);
$img_data = wp_get_attachment_image_src($thumb_id, 'full');
if (!$img_data) return;
$img_url = $img_data[0];
// WebP fallback
$img_webp = preg_replace('/\.(jpg|jpeg|png)$/i', '.webp', $img_url);
$upload = wp_get_upload_dir();
$has_webp = false;
if (!empty($upload['baseurl']) && !empty($upload['basedir'])) {
$webp_path = str_replace($upload['baseurl'], $upload['basedir'], $img_webp);
static $webp_cache = [];
if (!isset($webp_cache[$webp_path])) {
$webp_cache[$webp_path] = ($webp_path && file_exists($webp_path));
}
$has_webp = $webp_cache[$webp_path];
}
// LCP only first image on homepage
static $lcp_done = false;
$is_lcp = false;
if (is_home() || is_front_page()) {
if (!$lcp_done) {
$is_lcp = true;
$lcp_done = true;
}
}
$priority = $is_lcp ? 'high' : 'auto';
echo '';
if ($has_webp) {
echo '';
}
echo '
';
echo '';
}
/* ──────────────────────────────────────────────
IMDb / HD badge
────────────────────────────────────────────── */
function render_imdb($post_id) {
$imdb = get_post_meta($post_id, '_film_imdb', true);
if (preg_match('/>([\d\.]+)', $imdb, $m)) {
echo '⭐ ' . esc_html($m[1]) . '';
} else {
echo 'HD';
}
}
/* ──────────────────────────────────────────────
Categoria principală
────────────────────────────────────────────── */
function render_category($post_id) {
$cats = get_the_category($post_id);
$label = '🎬';
$class = 'film-cat';
$flag_svg = '';
if (!empty($cats)) {
foreach ($cats as $cat) {
if ($cat->term_id == 54 || $cat->parent == 54) {
$label = 'Serial';
$class = 'serial-cat';
break;
}
if ($cat->term_id == 5390 || $cat->parent == 5390) {
$label = $flag_svg;
$class = 'dublate-cat';
}
if ($cat->term_id == 9592 || $cat->parent == 9592) {
$label = $flag_svg;
$class = 'dublate-cat';
}
if ($cat->term_id == 1 || $cat->parent == 1) {
$label = 'Film';
$class = 'film-cat';
}
}
}
echo '' . $label . '';
}
/* ──────────────────────────────────────────────
Titlu overlay
────────────────────────────────────────────── */
function render_video_info_box($post_id) {
$title = get_the_title($post_id);
if (!$title) return;
echo '
' . esc_html($title) . '
';
}
/* ──────────────────────────────────────────────
Categorii multiple
────────────────────────────────────────────── */
function render_categories($post_id) {
$cats = get_the_category($post_id);
if (!empty($cats)) {
$names = [];
foreach ($cats as $c) {
$names[] = esc_html($c->name);
}
echo '' . implode(', ', $names) . '
';
}
}
/* ──────────────────────────────────────────────
PRELOAD LCP IMAGE (HOME ONLY)
────────────────────────────────────────────── */
add_action('wp_head', function() {
if (!is_home() && !is_front_page()) return;
$posts = get_posts([
'numberposts' => 1,
'no_found_rows' => true
]);
if (empty($posts)) return;
$thumb_id = get_post_thumbnail_id($posts[0]->ID);
if (!$thumb_id) return;
$img = wp_get_attachment_image_src($thumb_id, 'full');
if (!$img) return;
echo '' . "\n";
}, 1);
Letters to Juliet - Scrisori către Julieta (2010) online subtitrat