// ================================
// 🔹 Menú dinámico de categorías con iconos
// ================================
function rc_menu_subcategorias() {
if (is_single() || is_category()) {
$categoria_actual = null;
// Si estamos en un artículo → obtener categoría principal
if (is_single()) {
$categories = get_the_category();
if (!empty($categories)) {
$categoria_actual = $categories[0];
}
}
// Si estamos en página de categoría
if (is_category()) {
$categoria_actual = get_queried_object();
}
if ($categoria_actual) {
// CASO 1: Categoría padre → mostrar solo sus subcategorías directas
if ($categoria_actual->parent == 0) {
$subcats = get_categories(array(
'taxonomy' => 'category',
'parent' => $categoria_actual->term_id,
'hide_empty' => false,
));
if ($subcats) {
echo '';
}
}
// CASO 2: Subcategoría o Sub-subcategoría
else {
$parent_id = $categoria_actual->parent;
// Obtener todas las subcategorías del padre inmediato
$hermanas = get_categories(array(
'taxonomy' => 'category',
'parent' => $parent_id,
'hide_empty' => false,
));
if ($hermanas) {
echo '';
}
}
}
}
}
// Insertar menú al inicio del contenido
function rc_insertar_menu_subcategorias($content) {
if (is_single() || is_category()) {
ob_start();
rc_menu_subcategorias();
$menu = ob_get_clean();
return $menu . $content;
}
return $content;
}
add_filter('the_content', 'rc_insertar_menu_subcategorias');
Jacuzzi archivos - RecursosCAD
Saltar al contenido