¿Existe alguna forma de recuperar la plantilla que llama a un partial?

21 feb 2015, 11:42:27
Vistas: 75
Votos: 0

Si incluyo un partial dentro de header.php de esta forma:

    <?php get_template_part('templates/social-icons'); ?>

¿Existe alguna forma de recuperar el nombre de la plantilla header.php dentro de este partial? Es decir, ¿el nombre de la plantilla que está incluyendo social-icons.php?

Quiero recuperar dinámicamente el nombre 'header.php' dentro de social-icons.php para poder incluir este partial en otros lugares y reaccionar según la plantilla que lo está llamando.

¿Quizás usando funciones de PHP como get_included_files() o pathinfo()?

0
Todas las respuestas a la pregunta 1
0

Después de encontrar esta respuesta, opté por:

$template_tree = mytheme_get_template_tree();
$total = count($template_tree); //contar los elementos en el array
end($template_tree); //establecer el puntero al final del array
$immediate_parent = basename(prev($template_tree)); //obtener el nombre del archivo del penúltimo elemento

Luego en un plugin / functions.php

function mytheme_get_template_tree()
{
    $included_files = get_included_files();
    $stylesheet_dir = str_replace( '\\', '/', get_stylesheet_directory() );
    $template_dir   = str_replace( '\\', '/', get_template_directory() );

    foreach ( $included_files as $key => $path ) {

        $path = str_replace( '\\', '/', $path );

        if ( FALSE === strpos( $path, $stylesheet_dir ) && FALSE === strpos( $path, $template_dir ) ) {
            unset( $included_files[ $key ] );
        }
    }

    return $included_files;

}

Todavía estoy interesado en escuchar sobre enfoques alternativos.

21 feb 2015 12:38:32