WordPress.org

Ready to get started?Download WordPress

Forums

Display template by file name (6 posts)

  1. shua
    Member
    Posted 7 years ago #

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

  2. whooami
    Member
    Posted 7 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
    Member
    Posted 7 years ago #

    you could try this:

    <?php
    echo $_SERVER['PHP_SELF'];
    ?>

  4. shua
    Member
    Posted 7 years ago #

    muskokee,
    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
    Member
    Posted 7 years ago #

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

    get_page_template

  6. gimperdaniel
    Member
    Posted 6 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

Tags