How To To Include Template Files In WordPress


Sponsored Links




Something that really interesting in WordPress is Custom Page Templates. With custom page templates we can create unique WordPress Blog much easier. Now we will share many common use to include template files in WordPress.

Include Template in WordPress - Pixie Lott Cute

Include Template in WordPress - Pixie Lott Cute

Inserting Using PHP Style

This is standard code using PHP include

include(TEMPLATEPATH . 'template-name.php');

Load Template

This is part of WordPress System we can use load_template(); this code will run without check the original files and will be auto executed

load_template(TEMPLATEPATH . '/template-name.php');

Locate Template Method

This is much better method than load_template(), this method will check the files available or not

locate_template($template_names, $load);

Why this method much better, because on this method we can added some parameter too

Get Query Template

With get_query_template() you can get themplate without write complete name. You can only write the name of the files

include(get_query_template('template-name'));

You can also get / call WordPress standard theme files such as 404, tag, category, search with this code get_*_template() change * with the theme name, example

include(get_404_template());
// will give the same result
include(get_query_template('404'));

Get Template Part

And this is fresh function on WordPress 3.0 this function called get_template_part(); use this code like this example

get_template_part($slug, $name);

More details about this functions, This function will include file named “{slug}-{name}.php”. The $name is optional, and if it’s empty, the function will include file named “{slug}.php”. You can see this is the way Gamelan WordPress Theme uses for including loop:

get_template_part('loop'); // general loop, file 'loop.php'
get_template_part('loop', 'index'); // loop for index, file 'loop-index.php'
get_template_part('loop', 'single'); // loop for single post, file 'loop-single.php'

That’s it, now you can choose which one that prefer and suitable for your WordPress Project, now include template files in WordPress much easier right? Thanks for Deluxe Blog Tips for share this tips

Pictures source Egotastic

Subscribe to Full RSS Feed

RSS FeedIf you thing this article useful, please consider subscribing to our RSS Feed or e-mail updates and stay updated with us. You can also follow @WPTricksNet on twitter for latest updates.

About WP Tricks

We are WordPress Family, we collected and writed useful tips and tricks for you WordPress. We share it for you...

Related Tips and Trick from Local Data and on The Net

Stepping Into Templates « WordPress Codex

Most WordPress Themes include a variety of template files within other templates to generate the web pages on the site. The following template files are typical for the Read More

5 Ways To Include Template Files In WordPress - Deluxe Blog Tips

As long as you work with WordPress, you'll realize that some code is repeated itself many times, like the loop. The new Twenty Ten theme in WordPress 3.0 Read More

Include Tags « WordPress Codex

PHP has a built in include() statement for this purpose, but these WordPress template tags make including certain specific files much easier. See Using Themes and Theme Read More

Include Wordpress Template Files In Your Theme

Include custom files in your Wordpress theme by using an in-built Wordpress function get_template_part instead of using the standard PHP include function. Read More

5 Ways To Include Template Files In WordPress | ..::VN Support::..

As long as you work with WordPress, you'll realize that some code is repeated itself many times, like the loop. The new Twenty Ten theme in WordPress 3.0 has Read More


4 Responses to How To To Include Template Files In WordPress

  1. Toney Wister says:

    This post has been an eye opener; I’ll add it to my :)

  2. Workathomer says:

    Can you help me out? I’m looking for ways to make a template for WP older posts. It goes like /page/2, page/3 etc… How to make a custom template for that?

    thx

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>