0

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(); 
$wp_query->query('post_type=page');
while ($wp_query->have_posts()) : $wp_query->the_post();
    get_template_part('templates', 'template_slug');
endwhile;

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

Any help is more than appreciated!

2
  • Well, have you tried running it? Did it not work? :)
    – Rarst
    Commented Jan 11, 2014 at 16:19
  • Hi @Rarst, it did work. I forgot to update the thread.
    – brubs
    Commented Jan 11, 2014 at 17:45

1 Answer 1

0

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.

1
  • 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.
    – brubs
    Commented Dec 17, 2013 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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