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.

I'm pretty much a WP newbie, and I've noticed that in a lot of themes, there is the exact same code for displaying posts in three different places (single.php, archive.php, index.php etc)

This just bugs me. It doesn't seem right to me, a programmer always trying to code as efficiently as possible.

What is the best way to generalize the layout for posts, preferably as a WordPress integrated/native function?

share|improve this question
    
inefficient in what sense? number of lines or ease in which one is able to maintain and modify it? –  Milo Aug 23 '11 at 16:48
    
Mainly the latter, and for me it seems like these kinds of things just should be templated anyway, why type (copy) it out thrice? –  CookieMonster Aug 23 '11 at 17:01
    
look into the themes Twenty Ten and Twenty Eleven, how these use get_template_part(). –  Michael Aug 23 '11 at 19:27
    
@Michael Ah, thanks, that helps a lot :) –  CookieMonster Aug 23 '11 at 21:24

1 Answer 1

up vote 2 down vote accepted

you could move the loop content into its own file and share that between the different template files using get_template_part()

share|improve this answer
    
Yep, this turned out to be what I was looking for. Thanks :) –  CookieMonster Aug 23 '11 at 21:24

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.