How to recognise on which site the content is being rendered?

I’ve created a child theme basing on twenty twelve.

Since I present the content a little bit different on home and on the archive page, I’d like to know inside content-[format].php on which page the post is being rendered. Then, I can decide which image size I can present.

Read More

How can I know it?

Related posts

Leave a Reply

1 comment

  1. 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;
    }