Prueba de Shortcode [roi_post_grid]
+ +Test 1: Grid básico (9 posts)
+ + ++ +
Test 2: 6 posts en 2 columnas
+ + ++ +
diff --git a/Admin/PostGrid/Infrastructure/Ui/PostGridFormBuilder.php b/Admin/PostGrid/Infrastructure/Ui/PostGridFormBuilder.php index e99112c1..c9c4e396 100644 --- a/Admin/PostGrid/Infrastructure/Ui/PostGridFormBuilder.php +++ b/Admin/PostGrid/Infrastructure/Ui/PostGridFormBuilder.php @@ -33,14 +33,15 @@ final class PostGridFormBuilder // Columna izquierda $html .= '
'; + $html .= ' Usa este shortcode para insertar grids de posts en cualquier pagina o entrada. '; + $html .= ' Los estilos se heredan de la configuracion de este componente.'; + $html .= '
'; + + // Uso basico + $html .= ''; + $html .= ' '; + $html .= ' Uso basico (9 posts, 3 columnas)'; + $html .= '
'; + $html .= '[roi_post_grid]';
+ $html .= ' '; + $html .= ' '; + $html .= ' Filtrar por categoria'; + $html .= '
'; + $html .= '[roi_post_grid category="precios-unitarios"]';
+ $html .= ' '; + $html .= ' '; + $html .= ' 6 posts en 2 columnas'; + $html .= '
'; + $html .= '[roi_post_grid posts_per_page="6" columns="2"]';
+ $html .= ' '; + $html .= ' '; + $html .= ' Con paginacion'; + $html .= '
'; + $html .= '[roi_post_grid posts_per_page="12" show_pagination="true"]';
+ $html .= ' '; + $html .= ' '; + $html .= ' Filtrar por etiqueta'; + $html .= '
'; + $html .= '[roi_post_grid tag="tutorial"]';
+ $html .= ' '; + $html .= ' '; + $html .= ' Ejemplo completo'; + $html .= '
'; + $html .= '[roi_post_grid category="cursos" posts_per_page="6" columns="3" show_meta="false" show_categories="true"]';
+ $html .= ' '; + $html .= ' '; + $html .= ' Atributos disponibles'; + $html .= '
'; + $html .= '| Atributo | Default | Descripcion |
|---|---|---|
posts_per_page | 9 | Cantidad de posts |
columns | 3 | Columnas (1-4) |
category | - | Slug de categoria |
exclude_category | - | Excluir categoria |
tag | - | Slug de etiqueta |
author | - | ID o username |
orderby | date | date, title, rand |
order | DESC | DESC o ASC |
show_pagination | false | Mostrar paginacion |
show_thumbnail | true | Mostrar imagen |
show_excerpt | true | Mostrar extracto |
show_meta | true | Fecha y autor |
show_categories | true | Badges categoria |
excerpt_length | 20 | Palabras extracto |
exclude_posts | - | IDs separados por coma |
offset | 0 | Saltar N posts |
id | - | ID unico (multiples grids) |
class | - | Clase CSS adicional |
%s
%s
', esc_html($excerpt)); + } + + private function buildPaginationHTML(\WP_Query $query, array $options): string + { + $id = $options['id'] ?? ''; + $queryVar = !empty($id) ? "paged_{$id}" : 'paged'; + $currentPage = max(1, (int) get_query_var($queryVar, 1)); + $totalPages = $query->max_num_pages; + + $html = ''; + + return $html; + } + + private function toBool(mixed $value): bool + { + if (is_bool($value)) { + return $value; + } + return $value === 'true' || $value === '1' || $value === 1; + } +} diff --git a/Shared/Infrastructure/Wordpress/PostGridShortcodeRegistrar.php b/Shared/Infrastructure/Wordpress/PostGridShortcodeRegistrar.php new file mode 100644 index 00000000..4fc3f39a --- /dev/null +++ b/Shared/Infrastructure/Wordpress/PostGridShortcodeRegistrar.php @@ -0,0 +1,95 @@ +sanitizeAttributes($atts); + + // Obtener paged desde query var si existe + $id = $atts['id'] ?? ''; + $queryVar = !empty($id) ? "paged_{$id}" : 'paged'; + $atts['paged'] = max(1, (int) get_query_var($queryVar, 1)); + + // Crear request DTO + $request = RenderPostGridRequest::fromArray($atts); + + // Obtener UseCase desde DIContainer + $container = DIContainer::getInstance(); + $useCase = $container->getRenderPostGridUseCase(); + + return $useCase->execute($request); + } + + /** + * Sanitiza atributos del shortcode + * + * @param array|string $atts + * @return array