Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

What is best practice for WP with regard to using loop.php (loop-single.php, etc) versus looping inside the template file? Does it matter with regard to efficiency or ?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

Depends on whether you would use that single-loop in more places. If you're only using it in one place and that will remain the case, do it within single.php, if you're going to be reusing it elsewhere, I'd highly suggest using a single-loop template part.

share|improve this answer
    
Ok. The idea being if it's a loop that will be utilized in many places put it in a separate loop file for central access. Thanks brotha! –  Devise Sep 22 '11 at 13:52
    
JDV, I also just noticed that WP's default TwentyTen theme uses separate loop files, and TwentyEleven does not. This confused me to a degree .. any short idea on what their thinking was with dropping the loop files? –  Devise Sep 22 '11 at 14:00
    
To be honest, I don't know their thinking. I know I use a system of different custom post types, and I use the snippets to make it easy to make, for instance, search result pages or other custom listings. What I do is use a theme partial that has the post_types name in it, so I do this: get_template_part( 'partials/loop' ); And then in that loop partial, I do this: while ( have_posts() ) : the_post(); get_template_part( '/partials/short', $post->post_type ); endwhile; // End the loop. This makes it very easy for me to make changes to the loop and add CPT's... –  Joost de Valk Sep 26 '11 at 12:24
add comment

No, it's just a Q of organizing your theme files. It's template vs. template part. Later will do some searching inside your parent & child theme and then include your template part, but that doesn't do much perfomanze decrease.

share|improve this answer
add comment

Your Answer

 
discard

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.