ThemeShaper Forums » Thematic

[closed]

Problem including external files into templates?

(3 posts)
  • Started 4 years ago by jfacemyer
  • Latest reply from jfacemyer
  • This topic is resolved

Tags:

  1. jfacemyer
    Member

    I've created a common-header.php and common-footer.php file for including in each of my template pages (so that I don't have to change them all when I want to edit the basic theme structure, and the templates are much easier to edit, etc).

    Is there any problem with including files like this:

    --------------

    <?php
    require_once('common-header.php');

    // action hook for placing content above the index loop
    thematic_above_indexloop();

    // action hook creating the index loop
    thematic_indexloop();

    // action hook for placing content below the index loop
    thematic_below_indexloop();

    require_once('common-footer.php');
    ?>

    --------------

    Or is there a better way to do this? I ask because, it's such a great way to simplify the code (if it's valid) that I'm surprised it's not done already by default.

    Thanks!

    Posted 4 years ago #
  2. I don't think there's a problem doing it that way, I'm doing pretty much the same thing, but instead of hard-coding the template files, i'm adding my additions via functions.php. Here's a rough example:

    //add stuff below header
    function childtheme_common_header() {
    	if (is_page_template('front-page.php') ) {
    		    include "common-header.php";
    			}
    		}
    	add_action('thematic_belowheader' , 'childtheme_common_header',2);
    Posted 4 years ago #
  3. jfacemyer
    Member

    Thanks.

    Just wondering: is there a reason you're doing it via functions.php? It seems like a lot more hassle (unless you plan on changing the names of the php files a lot, or are adding multiple php includes which may be changing).

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.