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 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
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


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.