WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I´m developing a single page theme and want to render all pages with their respective templates on a single page. I know I could make a query and write the markup for the respective page, but I prefer separate all templates in files. What I want is to make the loop and load the template-*.php file for each page. Is that possible?

To clarify this a little bit, below follows an example of what I want:

$query = new WP_Query(); 
while ($wp_query->have_posts()) : $wp_query->the_post();
    get_template_part('templates', 'template_slug');

and in the while loop output not only the content, but the content in teh right markup.

Any help is more than appreciated!

share|improve this question
Well, have you tried running it? Did it not work? :) – Rarst Jan 11 '14 at 16:19
Hi @Rarst, it did work. I forgot to update the thread. – Drala Jan 11 '14 at 17:45
up vote 0 down vote accepted

Something like this if you want to call mytemplate.php:

get_template_part( 'template');

Or something like this if you want to call content-mytemplate.php:

get_template_part( 'content', 'mytemplate' );

I hope that this will help you.

share|improve this answer
Thanks for the input @pendjer What I want to know is how to put the get_template_path() method inside the while loop. I updated my question to illustrate this. – Drala Dec 17 '13 at 18:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.