Display template by file name (6 posts)

  1. shua
    Posted 8 years ago #

    Is there a way to grab the file name of the template being used for the current page/single?

  2. whooami
    Posted 8 years ago #

    current page/single?

    what is that?

    if you have one, page.php handles pages.
    if you have one, single.php handles single post views

    I realize that doesnt answer your question, there is a way to do that, yes, but it's much easier to just tell you the above,

  3. muskokee
    Posted 8 years ago #

    you could try this:

    echo $_SERVER['PHP_SELF'];

  4. shua
    Posted 8 years ago #

    thx for the reply! in placing the code...

    index.php is returned for each and every page.

    To clarify, I am looking for the template filename.

    I have created custom page templates, and I would like to write some conditions specific to a template filename. For example if the template has 'form' in its name then do xy or z.

  5. shua
    Posted 8 years ago #

    for anyone wanting the solution, try this on for size:


  6. gimperdaniel
    Posted 8 years ago #

    Thanks for finding your own question out Shua...I was wondering the same thing. And if you want to get just the name of the file instead of the path. I used the following:

    $temp = get_page_template();
    $path = pathinfo($temp);
    $temp = $path['filename'] . "." . $path['extension'];

Topic Closed

This topic has been closed to new replies.

About this Topic