WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Template files within template files within template files not possible? (5 posts)

  1. alsd
    Member
    Posted 3 years ago #

    I want to place a set of template files in a sub-directory (snippets), so I have this:

    <?php include (TEMPLATEPATH '/snippets/file.php'); ?>

    But WordPress is showing a blank page.

    it works if I remove the sub-directory.
    <?php include (TEMPLATEPATH '/file.php'); ?>

    Can't find any references in Codex.

    Thanks!

  2. Digital Raindrops
    Member
    Posted 3 years ago #

    I think you are missing a check for the file and the (concatenate) period '.' and you can use include_once if you do not need the file loaded every refresh.

    <?php if(file_exists(TEMPLATEPATH .'/snippets/file.php')){include(TEMPLATEPATH .'/snippets/file.php');} ?>

    Note:
    If it is a child theme then TEMPLATEPATH is the Parent file directory, STYLESHEETPATH is the child's file directory.

    <?php if(file_exists(STYLESHEETPATH .'/snippets/file.php')){include(STYLESHEETPATH .'/snippets/file.php');} ?>

    David

  3. alsd
    Member
    Posted 3 years ago #

    HI Adeptris,

    Thanks so much! It works and thanks for the include_once tips.

  4. Digital Raindrops
    Member
    Posted 3 years ago #

    Cool mark it as resolved please! :)

  5. alsd
    Member
    Posted 3 years ago #

    Ah yes! Thanks for doing that for me! I didn't even notice there is an option to change a thread status.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.