You can use the global $template
. The following function returns the basename
of the template file being used: index
, archive
, etc.
function get_template_name_wpse_85011()
{
global $template;
$filename = basename( $template, '.php' );
return $filename;
}
And use it in your template with something like:
$templat = get_template_name_wpse_85011();
switch( $templat )
{
case 'index':
// do index
break;
case 'archive':
// do archive
break;
default:
break;
}