Support » Themes and Templates » Is it possible to call theme files other than header.php, footer.php and so on?

  • 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.

Viewing 10 replies - 1 through 10 (of 10 total)
  • use <?php include("feature.php"); ?>

    Thanks!
    I knew it had to be easy….

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

    How do I edit the get function?

    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!

    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.

    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.

    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

    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.

    Well I am sure glad that somebody explained it. 🙂

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Is it possible to call theme files other than header.php, footer.php and so on?’ is closed to new replies.