is_archive() || $main->is_home() || $main->is_search()); $zx_paged = max(1, (int) get_query_var('paged'), (int) get_query_var('page')); if ($use_main) { $query = $main; } else { $count = isset($settings['count']) && is_numeric($settings['count']) ? max(1, min(50, (int) $settings['count'])) : 6; $query = ThemeData::query(['post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $count, 'paged' => $zx_paged, 'ignore_sticky_posts' => true, 'no_found_rows' => false]); } $zx_posts = is_array($query->posts ?? null) ? $query->posts : []; $on = static fn(string $key): bool => !array_key_exists($key, $settings) || !empty($settings[$key]); $size = ThemeData::tag($settings['image_size'] ?? 'medium_large', ['thumbnail', 'medium', 'medium_large', 'large', 'full'], 'medium_large'); $title_tag = ThemeData::tag($settings['title_tag'] ?? 'h3', ['h2', 'h3', 'h4', 'h5', 'h6', 'p'], 'h3'); $meta = is_array($settings['meta'] ?? null) ? array_values(array_filter($settings['meta'], 'is_string')) : ['date']; $length = isset($settings['excerpt_length']) && is_numeric($settings['excerpt_length']) ? max(1, (int) $settings['excerpt_length']) : 20; $read_more = trim((string) ($settings['read_more'] ?? '')); $excerpt_tag = new \Zadex\Dynamic\Tags\PostExcerpt(); $cards = ''; foreach ($zx_posts as $zx_post) { if (!is_object($zx_post) || !isset($zx_post->ID)) { continue; } $zx_id = (int) $zx_post->ID; $url = (string) get_permalink($zx_post); $zx_title = wp_strip_all_tags((string) get_the_title($zx_post)); $card = ''; $has_thumb = false; if ($on('show_image') && function_exists('get_the_post_thumbnail')) { $img = (string) get_the_post_thumbnail($zx_post, $size, ['class' => 'zx-archive-posts__img', 'loading' => 'lazy', 'alt' => '']); if ($img !== '') { $has_thumb = true; $card .= ''; } } $body = ''; if ($on('show_title')) { $body .= '<' . tag_escape($title_tag) . ' class="zx-archive-posts__title">' . esc_html($zx_title !== '' ? $zx_title : __('(no title)', 'zadex')) . '' . tag_escape($title_tag) . '>'; } $parts = []; foreach ($meta as $zx_m) { if ($zx_m === 'date') { $parts[] = ''; } elseif ($zx_m === 'author') { $parts[] = ''; } elseif ($zx_m === 'comments') { $n = (int) get_comments_number($zx_post); /* translators: %s: number of comments */ $parts[] = '' . esc_html(sprintf(_n('%s comment', '%s comments', $n, 'zadex'), number_format_i18n($n))) . ''; } elseif ($zx_m === 'category' && function_exists('get_the_category')) { $cats = get_the_category($zx_id); if (is_array($cats) && $cats) { $parts[] = '' . esc_html((string) $cats[0]->name) . ''; } } } if ($parts) { $body .= '
'; } if ($on('show_excerpt')) { $excerpt = (string) $excerpt_tag->render(['length' => $length], \Zadex\Dynamic\Context::for_post($zx_id)); if ($excerpt !== '') { $body .= '' . esc_html($excerpt) . '
'; } } if ($read_more !== '') { $body .= '' . esc_html($read_more) . ' ' . esc_html($zx_title) . ''; } $card .= '' . esc_html(trim((string) ($settings['empty_text'] ?? '')) ?: __('Nothing found.', 'zadex')) . '
'; echo wp_kses('