I’m wondering if there is any way to use get_template_part() with folders? My main folder has a lot of files now because I put every re-usable element in a separate file. I’d like to put them in folders then.
There is no information about that in Codex: http://codex.wordpress.org/Function_Reference/get_template_part
In fact you can, I have a folder in my theme directory called
/partials/
in in that folder I have files such aslatest-articles.php
,latest-news.php
andlatest-statements.php
and I load these files usingget_template_part()
like:Just dont forget to omit the
.php
from the file name.I’m afraid not. If in codex isn’t something you would like to know, try to follow the link to the source and have a look yourself to the code and try to manage it out.
I had a look and the get_template_part function is defined as below:
From this, you can read out, that get_template_part function just creates an intended php file name and calls function locate_template. This in not useful, so I had a look also on locate_template function:
Get locate template searches for php file called from get_template_part. But you can call locate_template directly from you code. And this is useful.
Try out this code instead of get_template_part(‘loop-sigle.php’) function (your file is located in mydir inside your theme):
The notes of function
get_template_part()
says:Wich allows you to make use of
locate_template()
, wich says:If you define
TEMPLATEPATH
with the subdirectory you want to use,get_template_part()
will search for the files in your subdirectory.