term_id : 0;
}
function fea_recop_title(string $raw): string {
return function_exists('fea_title') ? fea_title($raw) : $raw;
}
function fea_recop_render(array $atts = []): string {
$atts = shortcode_atts([
'cat' => '',
'per_page' => (string) FEA_RECOP_DEFAULT_PER_PAGE,
'group' => 'year',
'order' => 'desc',
], $atts, 'fea_recopilatorio');
$term_id = fea_recop_resolve_term($atts['cat']);
if (!$term_id) return '
Recopilatorio no disponible.
';
$per_page = max(20, min(500, (int) $atts['per_page']));
$order = strtolower($atts['order']) === 'asc' ? 'ASC' : 'DESC';
$paged = isset($_GET['recop']) ? max(1, (int) $_GET['recop']) : 1;
$q = new WP_Query([
'post_type' => 'post',
'post_status' => 'publish',
'cat' => $term_id,
'posts_per_page' => $per_page,
'paged' => $paged,
'orderby' => 'date',
'order' => $order,
'ignore_sticky_posts' => true,
'no_found_rows' => false,
]);
if (!$q->have_posts()) {
wp_reset_postdata();
return 'Todavía no hay entradas en esta sección.
';
}
$by_year = ($atts['group'] === 'year');
$html = '';
$cur_year = null;
$open = false;
while ($q->have_posts()) {
$q->the_post();
if ($by_year) {
$y = get_the_date('Y');
if ($y !== $cur_year) {
if ($open) $html .= '';
$html .= '
' . esc_html($y) . '
';
$cur_year = $y; $open = true;
}
} elseif (!$open) {
$html .= ''; $open = true;
}
$title = fea_recop_title(get_the_title());
$html .= '- ' . esc_html($title) . ''
. ' ' . esc_html(get_the_date('j M Y')) . '
';
}
if ($open) $html .= '
';
wp_reset_postdata();
// Paginación propia
$total_pages = (int) $q->max_num_pages;
if ($total_pages > 1) {
$html .= '';
}
$html .= '
';
return $html;
}
add_shortcode('fea_recopilatorio', 'fea_recop_render');
// ── [fea_multimedia_indice] — galería visual de multimedia (issue #110) ──────
// Sustituye la página intermedia /multimedia/ (4 enlaces) por la lista directa
// de los artículos de las categorías multimedia, con preview visual (miniatura
// de YouTube o primera imagen del contenido) + extracto, para invitar al clic.
/** Extrae una preview del contenido: ['type'=>'video'|'image'|'none','src'=>url]. */
function fea_mm_preview(string $content): array {
// 1) Vídeo de YouTube embebido → miniatura hqdefault
if (preg_match('~(?:youtube(?:-nocookie)?\.com/(?:embed/|watch\?v=)|youtu\.be/)([A-Za-z0-9_-]{6,})~', $content, $m)) {
return ['type' => 'video', 'src' => 'https://img.youtube.com/vi/' . $m[1] . '/hqdefault.jpg'];
}
// 2) Vimeo → sin thumbnail server-side fiable; marcar como vídeo sin src
if (preg_match('~vimeo\.com/(?:video/)?(\d+)~', $content)) {
return ['type' => 'video', 'src' => ''];
}
// 3) Primera imagen del contenido
if (preg_match('~
]+src=["\']([^"\']+)["\']~i', $content, $m)) {
return ['type' => 'image', 'src' => $m[1]];
}
return ['type' => 'none', 'src' => ''];
}
function fea_mm_indice_render(array $atts = []): string {
$atts = shortcode_atts([
'cats' => '1649,26', // Multimedia + Índice multimedia
'per_page' => '24',
], $atts, 'fea_multimedia_indice');
$cats = array_filter(array_map('intval', explode(',', $atts['cats'])));
if (!$cats) return '';
$per_page = max(6, min(60, (int) $atts['per_page']));
$paged = isset($_GET['mmpag']) ? max(1, (int) $_GET['mmpag']) : 1;
$q = new WP_Query([
'post_type' => 'post',
'post_status' => 'publish',
'category__in' => $cats,
'posts_per_page' => $per_page,
'paged' => $paged,
'orderby' => 'date',
'order' => 'DESC',
'ignore_sticky_posts' => true,
]);
if (!$q->have_posts()) {
wp_reset_postdata();
return 'Todavía no hay multimedia disponible.
';
}
$html = '';
$total_pages = (int) $q->max_num_pages;
wp_reset_postdata();
if ($total_pages > 1) {
$html .= '
';
}
$html .= '
'; // .fea-mm-wrap
return $html;
}
add_shortcode('fea_multimedia_indice', 'fea_mm_indice_render');
add_action('wp_head', function () {
if (is_admin()) return;
?>