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!

  • 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. – BrunoFenzl Jan 11 '14 at 17:45

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.

  • 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. – BrunoFenzl Dec 17 '13 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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