php - How do I Create a Custom Template File in Wordpress? -


i'm new wordpress , php gentle. i've searched wordpress documentation can't find answer this.

i need create section of html (and/or php) use in multiple page templates. i'm not sure called, want act same built-in wordpress template files header, sidebar, footer etc...

to clear, different creating own custom page template.

the usage this:

// index.php <?php get_header(); ?> // index page content <?php get_customrecentcontentsection(); ?> // more index page content <?php get_footer(); ?>   // customrecentcontentsection.php <div> // wordpress post query html php </div> 

i use <?php get_customrecentcontentsection(); ?> @ end of post template or anywhere else see fit.

currently, have duplicate code in index.php , post.php i'm trying rid of.

any appreciated. thanks!

first of all, to use function need create function in template's functions.php page.

then can create new .php file inside theme, maybe in folder called templates. name can call file function you've created:

function get_customrecentcontentsection(){     require('templates/yoursharedfile.php'); } 

the straight way print directly content.

function get_customrecentcontentsection(){     print 'your awesome content'; } 

i whould suggest download couple or 3 of reputated templates see how nice wordpress themers handle that. google best practices in wordpress theming.

it's not hard, reading couple of articles there!


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -