WordPress.org

Ready to get started?Download WordPress

Forums

Is it possible to call theme files other than header.php, footer.php and so on? (11 posts)

  1. gravestmor
    Member
    Posted 7 years ago #

    I would like to have a two-part header. So that I can turn off part of the header on some 'Pages'.

    Currently I call the header:

    <?php
    get_header();
    ?>

    following this I would like to call another file - "featured.php" by using:

    <?php
    get_featured();
    ?>

    I would be able to turn this off by not calling it on certain Pages. Is it possible to do this? So far I have only been able to call the header.php, sidebar.php and so on.

  2. cam_oai
    Member
    Posted 7 years ago #

    use <?php include("feature.php"); ?>

  3. gravestmor
    Member
    Posted 7 years ago #

    Thanks!
    I knew it had to be easy....

  4. Root
    Member
    Posted 7 years ago #

    There are some hazards to using includes. Might be best to edit the get function.

  5. gravestmor
    Member
    Posted 7 years ago #

    How do I edit the get function?

  6. moshu
    Member
    Posted 7 years ago #

    The get_header, get_sidebar etc. are functions defined in the WP engine.

    If you want to include a file that is in your theme folder, it is the best to use this (no need to mess with core file):
    <?php include (TEMPLATEPATH . '/feature.php'); ?>
    Use it literally, as it is, just change the included filenames!

  7. Root
    Member
    Posted 7 years ago #

    Well I do not agree entirely with moshu. include is a standard php command but it carries certain security ramifications. The get functions basically include but they carry out some checks first.

  8. moshu
    Member
    Posted 7 years ago #

    Hey, Root, that's fine (not agreeing with me) - because everybody knows I am not a coder :)
    I just provided what I have seen around a lot for calling additional files in the theme folder.

  9. cam_oai
    Member
    Posted 7 years ago #

    How do I edit the get function?

    Root? we are waiting for your answer, i use include() a lot and maybe u can show us how to use other ways?

    cheers

  10. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    In WordPress, the technically correct way to do it would be:
    load_template(TEMPLATEPATH . '/whatever.php');

    This loads the template file in question but with the additional security features. You don't actually need to create a get_whatever function to do this or anything, the load_template() call is perfectly acceptable.

    Note that using load_template() has security ramifications though. You'll lose your global variables, basically, so variables you made yourself won't pass through to the included file. All the WordPress ones you'll likely need will pass through though. This is why it's slightly more secure, an accidental security hole in the template is harder to exploit because most globals get eliminated through this mechanism.

  11. Root
    Member
    Posted 7 years ago #

    Well I am sure glad that somebody explained it. :)

Topic Closed

This topic has been closed to new replies.

About this Topic